21

I have an external 100 pages PDF document (not created by pdflatex) that I \includegraphics page-wise into a beamer presentation. The external PDF document employs white as page color, but I need the background to be transparent.

Ideally, this would be an option one could pass to \includegraphics – which I doubt to exist. However, I would also be open for some process involving external tools (pdftk, pdfjam, ImageMagick, Acrobat...).

16

I'm not sure about turning anything to transparent in a PDF. PDF is not an image format, so I guess the only way is to remove the background object entriely from the pages. You could do that manually (on every page) with Acrobat professional (and probably also some free pdf editors), but if you're lucky, the following may work:

  1. Convert your PDF into something readable with qpdf -qdf file.pdf file-redable.pdf.
  2. Look in there for the background object. (Luck needed at this point) More often than not, it will look somewhat like this:

    10 765.75 591.75 -729.75 re
    f
    

    That is, a filled rectangle large enough to cover the whole page.

  3. Experimentally remove it.

  4. Fix the resulting pdf with fix-qdf file-redable.pdf.
  5. Try whether it worked ;-)
  6. If you found the right object to remove, you can remove it in all places simultaneously with sed, for instance.
  • Aye. This may also be possible with Inkscape or Illustrator. – Martin Schröder Mar 31 '12 at 18:37
  • Thanks Stephan! While I managed to find the MacPorts package for qpdf, I have not yet found a tool named fix-pdf. Searching for it reveals a commercial Windows-only tool (fixpdf.org), which, however, does not look like being a command-line utility. Is that the one you refer too? – Daniel Apr 2 '12 at 11:11
  • @Daniel Argh, sorry. Typo. I meant fix-qdf which is part of the qdf bundle and responsible for fixing things like object tables after a "qdf" file has been edited. – Stephan Lehmke Apr 2 '12 at 11:59
  • :-) I have edited this also in your answer, so (after a while) we can delete these comments. As soon as I find some time I will try your suggestion. – Daniel Apr 2 '12 at 13:08
  • 1
    @Jef Only replace the first character of the lines to be deleted by a percent character (comment char in PDF or PostScript). The byte count must not be changed. – Heiko Oberdiek Sep 29 '15 at 11:20
3

I tried the qpdf as suggested, and it worked for me with libreoffice generated pdf. I created a script to remove the background. It may or may not work depending on version, etc, and can damage your PDF, so use at your risk

#!/bin/bash
if [ $# -ne 1 ] ; then
    echo "Use: $0 pdf_with_background.pdf"
    exit 1
fi

FILE="$1"
FILEQDF="$1.readable.pdf"
FILETMP="$1.tempfile.pdf"

# backups
#cp "$FILE" "$FILE.BAK"
# converts to readable format
qpdf -qdf "$FILE" "$FILEQDF"
# removes background
cat "$FILEQDF" | sed  '/^%% Contents for page/, /f\*/ { /^1 1 1 rg/, /f\*/ { s/^/%% /  }  }' >  "$FILETMP"
# fixes pdf
fix-qdf "$FILETMP" > "$FILE"
rm "$FILETMP"
rm "$FILEQDF"
  • +1 for taking this up again. Looks promising, but unfortunately does now work with my OpenOffice slides. (fix-qdf: <nam>.pdf.readable.qdf: not a pdf file) – Daniel Sep 29 '15 at 10:18
  • try looking at qdf for the pdf generated by openoffice and changing the sed expression; modified the script a bit, maybe it helps – Leh Sep 29 '15 at 11:15
  • Indeed it worked! – Alessandro Cuttin Apr 5 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.