jung-kurt / gofpdf

A PDF document generator with high level support for text, drawing and images
http://godoc.org/github.com/jung-kurt/gofpdf
MIT License
4.29k stars 772 forks source link

Add support for embedded files #335

Closed benoitkugler closed 4 years ago

benoitkugler commented 4 years ago

Hi, This PR adds support for embedded files, both at the root level via SetAttachments() or as page annotations via AddAttachmentAnnotation().

Summary of the changes :

Best, BK

jung-kurt commented 4 years ago

Thanks, @benoitkugler! This is a great feature but I encounter problems in my environment (Chrome OS) when viewing the example files. The first is likely a limitation of the Chrome native viewer: I can open the file but have no access to the embedded files. Is there a way to provide an interactive link like a bookmark to them?

The Chrome viewer fails to load the file annotations document and reports the rather unhelpful error Failed to load PDF document.. Any insights?

benoitkugler commented 4 years ago

Indeed I have the same error on Chromium Web Browser. I will look for the issue and be back when fixed :)

benoitkugler commented 4 years ago

So... I fixed a mistake (due to a bad usage of p.pages and p.newobj()), which means annotations shouldn't cause an error anymore. However, it seams that Chromium is unable to render file annotations... In comparison, Mozilla PDF.js, Okular or Evince (on linux) render the file properly. So it seems it's more a reader issue, but it maybe requires more tests ?

Is there a way to provide an interactive link like a bookmark to them?

Well, file annotations are precisely supposed to offer a "pointer on hover" linking to the file...

jung-kurt commented 4 years ago

Nice work, @benoitkugler! Thanks for the new feature.