@@ -1355,6 +1355,31 @@ static ByteSlice PdfLoadAttachment(fz_context* ctx, pdf_document* doc, int no) {
13551355 return res;
13561356}
13571357
1358+ // load embedded file data from a file attachment annotation by PDF object number
1359+ static ByteSlice PdfLoadAnnotationAttachment (fz_context* ctx, pdf_document* doc, int objNum) {
1360+ ByteSlice res;
1361+ fz_try (ctx) {
1362+ pdf_obj* obj = pdf_new_indirect (ctx, doc, objNum, 0 );
1363+ pdf_obj* fs = pdf_dict_get (ctx, obj, PDF_NAME (FS));
1364+ if (!fs) {
1365+ pdf_drop_obj (ctx, obj);
1366+ break ;
1367+ }
1368+ fz_buffer* buf = pdf_load_embedded_file_contents (ctx, fs);
1369+ if (buf) {
1370+ res.d = (u8 *)memdup (buf->data , buf->len );
1371+ res.sz = buf->len ;
1372+ fz_drop_buffer (ctx, buf);
1373+ }
1374+ pdf_drop_obj (ctx, obj);
1375+ }
1376+ fz_catch (ctx) {
1377+ fz_report_error (ctx);
1378+ logfa (" PdfLoadAnnotationAttachment(objNum=%d) failed\n " , objNum);
1379+ }
1380+ return res;
1381+ }
1382+
13581383// Note: make sure to only call with ctxAccess
13591384static fz_outline* PdfLoadAttachments (fz_context* ctx, pdf_document* doc, const char * path) {
13601385 fz_outline root{};
@@ -2725,9 +2750,9 @@ static void RebuildCommentsFromAnnotationsInner(fz_context* ctx, pdf_annot* anno
27252750 logf (" attachment: %s, num: %d\n " , attname, num);
27262751
27272752 auto dest = new PageDestination ();
2728- // TODO: kindDestinationAttachment ?
27292753 dest->kind = kindDestinationLaunchEmbedded;
27302754 dest->value = str::Dup (attname);
2755+ dest->embedObjNum = num;
27312756
27322757 auto el = new PageElementDestination (dest);
27332758 el->pageNo = pageNo;
@@ -3982,6 +4007,15 @@ ByteSlice EngineMupdfLoadAttachment(EngineBase* engine, int attachmentNo) {
39824007 return res;
39834008}
39844009
4010+ ByteSlice EngineMupdfLoadAnnotAttachment (EngineBase* engine, int objNum) {
4011+ EngineMupdf* epdf = AsEngineMupdf (engine);
4012+ if (!epdf->pdfdoc ) {
4013+ return {};
4014+ }
4015+ ScopedCritSec scope (epdf->ctxAccess );
4016+ return PdfLoadAnnotationAttachment (epdf->Ctx (), epdf->pdfdoc , objNum);
4017+ }
4018+
39854019// if an elements fully obscures another, remove it from the list
39864020static bool RemoveHeWhoFullyContains (Vec<Annotation*>& els) {
39874021 int n = els.Size ();
0 commit comments