PDFTK: pdfs that display with bookmark panel open
Is it possible, with pdftk, to render a bookmarked PDF that opens with bookmarks displaying?
I did a little research on this topic and wanted to compile an answer with references.
-
According to this guy from this post claiming to be the
pdftk
maintainer, it's stated that:When using pdftk to assemble a new PDF from PDF pages or documents (via the cat operation), the new PDF does not have display settings. So the resulting PDF is displayed using the defaults set in your viewer's preferences.
source
So I think this means that if you created a new PDF document, or created a new PDF document with cat
operations, or started with a PDF document that did not already have this initial view metadata properties in it to start with, then PDFtk it'll open up in a "view" that's set to open however the default PDF viewing software tells it to open up. If there's no metadata in the document related to the Bookmark Panel view, then obviously it won't be able to utilize it regardless.
-
According to the PDFtk Man page there are two options that are related to metadata and bookmarks and another statement related to bookmarks.
dump_data
Reads a single input PDF file and reports its metadata, bookmarks (a/k/a outlines), page metrics (media, rotation and labels) and other data to the given output filename or (if no output is given) to stdout. Non-ASCII characters are encoded as XML numerical entities. Does not create a new PDF.
update_info < info data filename | - | PROMPT >
Changes the bookmarks and metadata in a single PDF’s Info dictionary to match the input data file. The input data file uses the same syntax as the output from dump_data. Non-ASCII characters should be encoded as XML numerical entities. This does not change the metadata stored in the PDF’s XMP stream, if it has one. For example:
pdftk in.pdf update_info in.info output out.pdf
If a PDF handle is given but no pages are specified, then the entire PDF is used. If no pages are specified for any of the input PDFs, then the input PDFs' bookmarks are also merged and included in the output.
source
So I think this means that if you have a PDF document with bookmark metadata that you need to use the dump_data
option first to export that metadata to a flat file. You will then use the flat file with that metadata in it with the update_info
option to put the correlated metadata from that file into the PDF file you create, etc.
Furthermore, if no pages are specified (e.g. cat
option) in the PDFtk operation then it sounds like the entire PDF document and it's correlated metadata including default "view" settings will be merged over to the output file.
I had the same question before I saw yours. The problem with dump_data and update_info is that the property your are looking for, which is PageMode, is not included in the dump_data output.
If you look in my question https://unix.stackexchange.com/questions/398806/how-to-display-bookmarks-in-the-initial-view-when-opening-a-pdf-file/399144#399144 you'll see that I used ( evermap.com/autometadata.asp) to provide a midway solution and then compare the modified/original files to see what the difference was.
Still no clean command-line solution
Best regards /Colm