3

I am currently facing some problem when I tried to import a PDF as a graphic. The PDF with some original text beside was first cropped to remove the text and then imported using \includegraphics.

enter image description here

However, as shown in the figure, the original text remained and could be 'seen' when highlighted (when viewing in PDF reader). In fact, by copying and pasting the text to a word file, the original text could be viewed again.

Anyone know what caused this and maybe the solution for it? (besides converting the PDF to image)

6
  • 2
    It is easy to extract a part from a bitmap image: you only need to take the pixels. It is quite difficult to extract parts from a vector graphic as the code can be spread around. You should try to recreate your image without the text. Nov 29, 2018 at 12:39
  • Have you tried editing the PDF to be included, e.g. using LibreOffice Draw, and removing the text? It seems the 'cropping' step didn't really remove the text. How did you crop the PDF?
    – chrisma
    Dec 1, 2018 at 10:18
  • perhaps try to extract the image rather from original pdf instead of cropping askubuntu.com/questions/150100/…
    – user4686
    Dec 1, 2018 at 10:34
  • with Adobe Reader on Mac OS X, you can select an embedded image, then control click to copy it to clipboard. Going to Preview.app you can "create from clipboard" (don't know exact English formulation). I guess this works only for bitmap graphics.
    – user4686
    Dec 1, 2018 at 10:48
  • Ironically the image you use says it all, In a PDF there can be a "background" layer then stacked layers of text and vectors then a "forground" layer usually the scanned image. during the crop the background and foreground may be visually cut but the layers sandwiched between can be retained. the cropping tool may have options to drop those layers but the simplest as others have stated is to "copy n paste" the image layer and use that. Note the quality can depend on zoom level so try to zoom in 200 or 400% prior to copy.
    – user170109
    Dec 1, 2018 at 13:31

2 Answers 2

2

What (likely) happened

It is very likely, that your imported PDF was imported with the complete content -- but part of that content was just hidden by applying a different 'CropBox' (smaller than the 'MediaBox' of the original PDF) to the import. This can be achieved by just manipulating a very small part of the PDF code.

How it typically happens

It typically happens when you use macOS' 'Preview' app to "crop" parts of the pages. And users often get fooled: they think they had removed everything which is now invisible and have protected their wider company secrets when sending such a page "extract" to a customer. However, a simple change of two numbers in a text editor will make all page content visible again!

How to better understand what happened

For understanding how this type of "cropping" works, imagine a page full of contents to be covered by a white sheet of paper. Now cut a little window into that sheet that lets you just see the "cropped" area. The rest of the content is not gone, but still there; it's just currently invisible and can be made visible again by simply removing the white sheet of paper with the little window in it. Since the PDF viewers do not really show you the white areas around the visible part your mind is easily fooled into imagining that the remaining content is gone for good. To really crop you'd have to cut away all the unwanted content from the original paper and burn it...

How to solve the problem

In order to make the content outside of such cropped areas really go away (and be permanently removed from the page's /Contents stream, you have to re-process the initial cropped page one more time. Running it through Ghostscript like this will achieve this result:

gs -sDEVICE=pdfwrite -o really-cropped.pdf seemingly-cropped.pdf

How to check if the solution worked

To verify, you should then run these two pdfinfo commands:

 pdfinfo -box seemingly-cropped.pdf
 pdfinfo -box really-cropped.pdf

Only that PDF file which has the same values for MediaBox and for CropBox can be guaranteed to not carry extra (hidden) content outside the area being displayed by PDF viewers. These ones you could savely import into your documents. All PDF files which have smaller CropBox-es than MediaBox-es may have extra invisible contents travelling with them....

0

I recently went through a similar situation, and luckily I managed to solve the problem. In my case, I needed to remove header and footer from PDFs to extract tables automatically - serch for 'tabula-py' Python package. The idea was to merge all PDF pages into a single page - search for 'pdfjam --nup' command - to fix badly formatted tables.

To crop the PDF margins, I used the 'pdfcrop' command from the 'texlive-extra-utils' package, available for Linux. After cropping the PDF margins, I used the 'pdftocairo' command to delete the invisible/hidden text content. To install 'pdftocairo' tool on Debian/Ubuntu distros, just run the following command:

sudo apt install poppler-utils

The tool is used by command line, and you can run it like this:

pdftocairo input.pdf output.pdf -pdf

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .