Yes, can confirm that this works perfectly!
It is true that you lose the TOC/Bookmarks this, but it is in fact very easy to restore these from the original PDF! You will need the following:
- The original Mongoose PDF (mong.pdf in explanation below)
- Your 'fixed' pdf using apastuszak's pdftocairo method (fixed.pdf in explanation below)
- pdftk
If you haven't already, first install the Java 'port' of pdftk using homebrew:
This will also install any necessary dependencies (mainly openjdk).
When this is installed it becomes a matter of extracting the TOC/bookmark data (well, there's a bit more in there than just that, but we're mainly interested in the bookmarks) for the original Mongoose PDF and merging this data with the fixed pdf file.
First you extract the data*:
Code:
pdftk /path/to/mong.pdf dump_data_utf8 output data.txt
Then you merge the extracted data with the pdftocairo output file:
Code:
pdftk /path/to/fixed.pdf update_info_utf8 /path/to/data.txt output Fixed_Bookmarks.pdf
Et voilà, the Fixed_Bookmarks.pdf will now be your desired fixed pdf with all the original bookmarks intact!
*Note that you can now easily manipulate this data file in a text editor in order to add your own bookmarks or to change the nesting level of existing bookmarks.