So, a very efficient way to try to write things is using Pandoc, which allows a user to write something in Markdown format and then convert it to a variety of markup languages, such as LaTeX, HTML, or even (g/t)roff. As I’m not very adept at LaTeX nor groff, I decided to try making a PDF from Markdown with pdfroff as my engine. The PDF rendered as expected, but I noticed that links and bookmarks were all positioned lower than they should be.
It turns out that Pandoc doesn’t compress the PDF files, so I was able to actually view the source code of the PDF. Playing around with the coordinates of the bookmarks, I was able to deduce that 38px North is all I would need to position the bookmarks properly. So, I tried to figure out how to do that.
This script repairs a pdf file generated by pdfroff which has misaligned co-ordinates for its bookmarks and anchor link. The key value to adjust here is the numbers in the string $1+50. Unlike a previous version of the script, this script generates everything necessary from the original PDF file and deletes all working files when done.
I wrote this script for my Linux system, so I think any UNIX-based system should be able to run the script, as long as the original pdf file is uncompressed with a program such as pdftk.
Just mark the script as executable...
chmod +x pdfroff_bookmarks_fix.sh
and then run the script with the PDF as the first argument
./pdfroff_bookmarks_fix.sh foo.pdf
The output should be foo_adjust.pdf
If the bookmarks still don't align perfectly with the coordinates of the paragraphs, just make adjustments to the number 50
in the string $1+50
and try again.
Please check out the two files included in the ./example
directory. bookmarks.pdf
was generated with Pandoc using the pdfroff compiler and its bookmark coordinates are wrong. bookmarks_adjust.pdf
is the PDF generated by this script with the proper bookmark coordinates.