gettalong / hexapdf

Versatile PDF creation and manipulation for Ruby
https://hexapdf.gettalong.org
Other
1.22k stars 70 forks source link

Embedding javascript into pdf #57

Closed iSunRise closed 5 years ago

iSunRise commented 5 years ago

Hello,

First of all thank you for great product, it works flawlessly in most situations.

I have a question, how can I add some js into pdf using hexapdf library?

Thanks in advance

gettalong commented 5 years ago

Thanks! Would love to hear where HexaPDF doesn't work flawlessly :grin:

As for your question: You can already do it manually but there are currently no built-in convenience methods for adding Javascript to the right objects. A quick glance at the spec seems to indicate that section 12.6.4.16 "Javascript Actions" would need to be implemented as well as support for these actions on the appropriate objects.

gettalong commented 5 years ago

@iSunRise I will close this issue. If you still have questions regarding this topic, please comment.

iSunRise commented 5 years ago

@gettalong hey, sorry I missed notification about this issue. I was able to get js from pdf (inserted it there using acrobat) but thought there's easier way to get it and out. Anyway, thank you for the answer. P.S. Regarding things which doesn't work property, I had to save pdfs without validation cause in 50% of my cases it fails with HexaPDF::Error: Validation error: Required field BaseFont is not set error. It's not critical, just FYI. Thanks

gettalong commented 5 years ago

@iSunRise No problem and thanks for the follow-up. If you like (and have time for it), you can tell me (privately per e-mail if needed) what you needed to do so that I can incorporate this information once I get around to implementing this part.

As for the BaseFont errors: If you have a PDF that exhibits this problem and that you could share with me, it would help me determine the cause.

iSunRise commented 5 years ago

@gettalong, thanks for the response, I don't think you should spend time on resolving that BaseFont error, I guess it's only because my pdfs often have fonts which are missing in hexpdf or os system. However, I have one more issue. If you're interested I can share some pdfs which fails with infinite loop error. They contains a svg image with an inner reference to itself. I didn't open an issue cause I was able to write a monkey-patch to avoid such problem.

gettalong commented 5 years ago

@iSunRise Yes, please share the PDFs so that I can have a look at them - thank you!

gettalong commented 5 years ago

The issue with the infinite loop is fixed with the commit https://github.com/gettalong/hexapdf/commit/5bd85913e49b39a6836a4136a215a1ce8db799d9

gettalong commented 5 years ago

@iSunRise I have released version 0.9.1 with the bug fix.