Coder Social home page Coder Social logo

tdavlinguist / pdfroff_bookmarks_fix Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 38 KB

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.

License: GNU General Public License v2.0

Shell 100.00%

pdfroff_bookmarks_fix's Introduction

Introduction

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.

What this script does

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.

Usage

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.

Examples

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.

pdfroff_bookmarks_fix's People

Contributors

tdavlinguist avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.