10

I usually prefer PDF images for my LaTeX documents because they are easy to crop/resize using Adobe professional. I am facing a weird problem. I modified one of the PDF images using Adobe professional by writing come comments using the pencil tool and added a rectangular box on the image and saved it. The LaTeX output is not showing the modification that I made to the image file but when i open the image file the modifications are still there. Did anyone face similar problems?

Martin Scharrer
  • 262,582

7 Answers7

6

One way to do this preserving the vector form would be to use the Adobe Acrobat "Preflight" tool, which allows you to "flatten" your comments ("Flatten forms and annotations"). I tried to show you an example, but it comes reversed! Maybe it's a bug of version X. :(

Another way inside Acrobat it's to open a console (Ctrl-J) and then execute the command flattenPages() which I can confirm it's working in my version of Acrobat and it's correctly compiled in vector form by pdfLaTeX. The output is like this.

A third option to selectively flatten your content would be one of the several scripts of the Adobe Exchange like this one (there's plenty of others) in case that

JorgeGT
  • 1,602
  • 12
  • 14
4

The problem is that the annotations are added to the PDF on a separate layer, in a way not handled by many tools that embed PDFs in other PS/PDF content. Thus you have to flatten the annotations - turn them to ordinary PDF primitives - for them to show up.

On OS X, the annotation flattening is done from Preview via "Export to PDF".

Here is the workflow I use to annotate photographs:

  1. Open any image file in Preview.
  2. Optionally reduce the size to keep the file size down.
  3. Export to PDF - this will be the editable annotated file.
  4. Open the PDF in Preview.
  5. Add annotations to the PDF. They are editable if you reopen the file later with Preview.
  6. Export to PDF - this will be the flattened file that shows up correctly in pdflatex output etc.
  • 2
    Thanks, however when I do this the exported PDF has an A4 or US Letter format, which the original file did not have ; in other words it puts the original content in a big white page. This makes it impractical for Latex purposes. Any solution? – Arthur Mar 19 '18 at 16:01
  • @Arthur You can crop it, although there is a way to use PdfKit directly to avoid the big white page problem I believe. It'd require some coding, though. – Kuba hasn't forgotten Monica Mar 19 '18 at 18:34
3

GhostScript can flatten PDFs. Try putting this in a file on your PATH (like /usr/local/bin/flattenpdf) and making it executable:

#!/bin/bash
gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sPDFPassword='' -dPDFSETTINGS=/prepress -dPassThroughJPEGImages=true -sOutputFile="${1%.*} (Flattened).pdf" "$1"

Then just use flattenpdf yourpdffile.pdf to create a flattened version.

also it removes password restrictions from PDFs

[EDIT Sept 2023] Following Ghostscript version 9.21 this does not work any more (gs preserves the annotation layer that is in a sense good), but there is a flag for that: -dPreserveAnnots=false. A new version of the script (that works for me) would be:

#!/bin/bash
gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sPDFPassword='' -dPDFSETTINGS=/prepress -dPassThroughJPEGImages=true -dPreserveAnnots=false -sOutputFile="${1%.*} (Flattened).pdf" "$1"
lehalle
  • 185
1

In Mac OS, crtl+p to print and 'save to pdf' work for me.

Lynne
  • 111
0

I met a similar problem when I add a line in my pdf using pdf editor, but the line didn't show in the pdf file generated from latex.

I just solved this problem by opening my pdf file using the Word, and then modify it using the Word. Then, the modified word can be resaved back to pdf, it works.

Amazing! You can try it.

Lei Li
  • 1
0

I had the same problem. I solved it by using the cutePDFwriter. Open the pdf file with annotations, then go crtl+p to print and use cutePDFwriter to save the file again. Then the annotations will be shown in the compiled file.

Luiz
  • 101
0

This simple solution worked for me. Print that annotated pdf and in the printer selection box, choose- 'Microsoft print to pdf'. This will flatten the pdf. Now, include the newly generated pdf in your latex.