boazsegev / combine_pdf

A Pure ruby library to merge PDF files, number pages and maybe more...
MIT License
734 stars 155 forks source link

Adding new named destinations and links #151

Closed dabidski closed 5 years ago

dabidski commented 5 years ago

I was wondering if there's a way to add new named destinations and links into loaded pdf pages. I couldn't find it in the docs.

Thanks in advance, David

boazsegev commented 5 years ago

Hi David,

The API doesn't officially support manipulating the PDF outline object, but it does allow you to "hack" the object and add named destinations / links if you know what you're doing.

This requires knowledge of the PDF standard and some fiddling with the deconstructed PDF tree provided by CombinePDF.

The pdf.outlines accessor object, along with the pdf.pages function should get you off to a good start, but it's a rocky road.

Good luck! BO.

P.S.

If you look at CombinePDF's internal code, you might notice the protected method merge_outlines. You might garner some insights about how to accomplish your desire by reviewing it.

If you do come up with an easy and safe API for this feature, feel free to propose a PR.

B.

https://github.com/boazsegev/combine_pdf/blob/f9b9f22a85458fac0f505b0eb6960e75f0742459/lib/combine_pdf/pdf_protected.rb#L278-L344

boazsegev commented 5 years ago

Hi David,

I'm assuming the answer was good enough and closing the issue.

Please feel free to re-open the issue or ask more questions if you need to.

Kindly, Bo.

dabidski commented 5 years ago

Hi Bo,

Sorry for the late reply. I think I'll need to go for a different solution.

Thanks for your input. Really appreciate it.

Regards, David