Ghostscript
Create bookmaeks
On my Ubuntu system, it’s impossible to use Adobe Acrobat to add pdf bookmarks. Usually, I substitute it with Foxit Reader but it seems that Foxit is not so compatible with Okular, my favorite pdf viewer. Finally I get the solution in stackoverflow and find the great power of Ghostscript. The references are as follows:
http://milan.kupcevic.net/ghostscript-ps-pdf/#marks
https://stackoverflow.com/questions/30304718/create-bookmarks-into-a-pdf-file-via-command-line
As far as bookmarks are concerned, Ghostscript does a good job. For instance, I would like to add bookmarks in the book called How to Read a Book.
First installation on Ubuntu.
sudo apt install ghostscript
Next I need to create a text file which contains the pdf information, including table of contents. The text file is named after HowtoRead
.
[ /Title (How to Read a Book)
/Author (Mortimer J. Adler & Charles Van Doren)
/Subject (Reading Tech)
/Keywords (reading)
/ModDate (unknown)
/CreationDate (unknown)
/Creator (unknown)
/Producer (unknown)
/DOCINFO pdfmark
[ /Page 1 /View [/XYZ null null null] /Title (Cover) /OUT pdfmark
[ /Page 3 /View [/XYZ null null null] /Title (Contents) /OUT pdfmark
[ /Page 17 /View [/XYZ null null null] /Title (1 The Activity and Art of Reading) /OUT pdfmark
[ /Page 30 /View [/XYZ null null null] /Title (2 The Levels of Reading) /OUT pdfmark
[ /Page 35 /View [/XYZ null null null] /Title (3 The First Level of Reading: Elementary Reading) /OUT pdfmark
[ /Page 45 /View [/XYZ null null null] /Title (4 The Second Level of Reading: Inspectional Reading) /OUT pdfmark
...
...
[ /Page 248 /View [/XYZ null null null] /Title (16 How to Read History) /OUT pdfmark
[ /Page 269 /View [/XYZ null null null] /Title (17 How to Read Science and Mathematics) /OUT pdfmark
[ /Page 284 /View [/XYZ null null null] /Title (18 How to Read Philosophy) /OUT pdfmark
[ /Page 310 /View [/XYZ null null null] /Title (19 How to Read Social Science) /OUT pdfmark
[ /Page 323 /View [/XYZ null null null] /Title (20 The Fourth Level of Reading: Syntopical Reading) /OUT pdfmark
[ /Page 351 /View [/XYZ null null null] /Title (21 Reading and the Growth of the Mind) /OUT pdfmark
[ /Page 361 /View [/XYZ null null null] /Title (APPENDIX A A Recommended Reading List) /OUT pdfmark
[ /Page 377 /View [/XYZ null null null] /Title (APPENDIX B Exercises and Tests at the Four Levels of Reading) /OUT pdfmark
Then combine the file with a PostScript or a PDF file, using Ghostscript command.
gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=withmarks.pdf \
HowtoRead.pdf HowtoRead
And withmarks.pdf
is the new pdf that has bookmarks. Maybe the creation of the text file is boring and a little complex, but it indeed helps me. If you are using Vim editor, things become simple. As for Ghostscript command, man ghostscript
or Official Documentation. Details about pdfmark can be found in pdfmark reference
Remove bookmarks
To remove unnecessary and stupid bookmarks, you can use the following commands on Ubuntu if Ghostscript has been installed:
pdf2ps filename.pdf
Remove the earlier pdf file and convert this .ps to .pdf.
ps2pdf filename.ps
Combine pdf
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dQUIET -sOutputFile=combined.pdf sub1.pdf sub2.pdf