Read more

How to repair a corrupt PDF

Dominik Schöler
November 12, 2014Software engineer at makandra GmbH

If you have issues with PDFs, fix them like this: pdftk <corrupted_file>.pdf output <fixed_file>.pdf

Background

Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

I had an issue where an included PDF would not show up in a document created with xelatex. This is the relevant line of LaTeX code:

  \AddToShipoutPicture*{ \includegraphics[width=21cm]{/home/dominik/code/ihero/public/system/stationery/original/stationery.pdf} }

The included PDF is a stationery for invoices which users can upload themselves. It did work until someone updated their stationery with a nearly-identical version. Now the stationery would be missing for no obvious reason. I suspected the PDF was somehow corrupted, and someone on StackExchange Show archive.org snapshot had the hint how to fix it: The pdf toolkit pdftk.

pdftk can do almost any PDF-related task as merging, splitting, rotating, decrypting, encrypting, filling forms, applying watermarks, reporting metadata and bookmarks, attaching files and ... repairing.

Resources

A valuable resource for debugging PDF problems seems to be the comprehensive Understanding the PDF format Show archive.org snapshot series. Have a look.

Posted by Dominik Schöler to makandra dev (2014-11-12 17:18)