Attaching files to PDFs with QPDF

Here's a demo that uses QPDF to embed the markdown source code of a file into the PDF generated by pandoc.

Using the example markdown file from the Markdown to reStructuredText example at https://pandoc.org/try/

I'm able to use pandoc to produce eg1.pdf and then attach eg1.md to eg1.pdf creating out.pdf. Notice in step 4 that the list of attachements output is shown:

  1. nix-shell -p pandoc qpdf
  2. pandoc -s eg1.md -o eg1.pdf
  3. qpdf eg1.pdf --add-attachment eg1.md -- out.pdf
  4. qpdf --list-attachments ../out.pdf
eg1.md -> 146,0
  1. qpdf --show-attachment=eg1.md ../out.pdf > fromPDF.md
  2. diff fromPDF.md ../eg1.md

I'm very grateful to Brian for pointing out QPDF to me when I went asking about attaching files to PDFs. Thanks, Brian!



Tags: PDF, pandoc, qpdf

← Back home