2

The graphicx package provides some very useful options for its all-powerful \includegraphics command, namely the trim and clip options.

With these, it's easily possible to trim and clip an included image, and if that image is a PDF file, the text of it is still selectable. Consider this simple example. Create a file called input.tex with the following contents, and run pdflatex on it:

\documentclass{standalone}
\begin{document}
Hello world!
\end{document}

Now, in a second file, the output of the first one can be easily included, trimmed and clipped like this:

\documentclass{article}
\usepackage{graphicx}

\begin{document}
here comes the text: \fbox{\includegraphics[trim=0em 0cm 1cm 0cm,clip=true]{input}}
\end{document}

The result is beautiful: good

However, the clip option doesn't seem to actually remove the contents from the PDF file, but rather hide them - they can still be accessed when selecting the text passages by mouse: strange

That is not very nice, especially if the clipped sections of the input.pdf include sensitive information that the receipients of the final file are not allowed to access. Is there any magical includegraphics option to solve this problem?

  • 2
    I learned my lesson and never use clipped images in documents anymore. In my case, it printed out on my printer just fine, but the production/distribution organizational printer (hundreds of copies) failed to clip properly. The doc had to be reissued. The sensitivity is another angle altogether that one must not forget. For other issues of sensitive content, you might check out my censor package, though it won't help you here. – Steven B. Segletes Oct 19 '16 at 18:06
  • True. Thanks for the suggestion, though! – carsten Oct 19 '16 at 18:15
  • 2
    My current workaround is: (1) write a small tex file with standalone and include, clip and trim the input as needed, then (2) call pdfcrop to get rid of any additional whitespace, then (3) convert it with pdf2ps and finally (4) convert it back with ps2pdf. This works to remove the elements outside the bounding box & keeps the image as a vector graphic, but is cumbersome as hell. – carsten Oct 19 '16 at 18:44
  • 1
    In general, PDF can include material in the file that is not ordinarily displayed (but can be revealed under certain circumstances). That is not specifically related to TeX or to any of its packages. Apparently, this is by design of PDF. When you clip/crop/trim material in a PDF, you are not physically removing its bytes; you are only making them hard to see. Analogy: If you look at a forest through a hole cut in a piece of paper, the trees you cannot see are still there, and can be seen if you move the hole. Your best bet is to cut you material down to size first. – user103221 Oct 20 '16 at 5:05
  • 1
    @StevenB.Segletes or use inkscape (FOSS) or Acrobat pro (commercial) to vector-edit the first pdf. – Chris H Oct 20 '16 at 13:16
2

What you want is destructive clipping. That can be only done by true PDF editors, e.g. Adobe Acrobat.

  • If you want a free solution, inkscape can do this (though it's possible Acrobat makes it more convenient) – Chris H Oct 20 '16 at 13:17

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.