boazsegev / combine_pdf

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

Option to remove Outline/Bookmarks while merging #133

Closed ghost closed 6 years ago

ghost commented 6 years ago

First of all, I appreciate your efforts. Is there an option which i can use to remove the outline/bookmarks while merging with another pdf.

Scenario: I have a pdf A1, with outline/bookmark Title, Cover, Author. In my second pdf A2, also has the same outline/bookmark. As of now after merging, the combined pdf has the same outlines repeated. Expectation: After merging, the combined pdf should have outlines only from the first pdf A1.

boazsegev commented 6 years ago

Hi @ltenzil ,

Thank you for opening this question.

Here's one possible hack, it accesses a protected method that returns the outline object and clears it. Try it with PDF number 2....:

pdf2.instance_variable_get(:@outlines).clear

If it works out well enough, I might add a public accessor for the next version.

Let me know how it goes and good luck!

Bo.

boazsegev commented 6 years ago

A quick update:

In the upcoming version, the protected outlines_object accessor method will be deprecated in favor of a public outlines accessor.

I've updated the example code I gave you so it directly accessed the internal variable.

pdf2.instance_variable_get(:@outlines).clear

I recommend that you use the public methods once version 1.0.8 is out.

B.

ghost commented 6 years ago

Hey @boazsegev ,

Sorry for late reply. I was out of town. Thank you Bo, it worked like a charm. Will definitely use the accessor, once the version is out. Take care. Hope you had great weekend.  

Thanks buddy, LT.