6

I have a PDF document, evidently produced using LaTeX, which has wide white margins and crop marks. I'd like to remove these margins and corresponding crop marks. Is there a tool to do it automatically?

EDIT Werner suggested to use pdfpages package to include PDF's pages in a LaTeX document. I should actually include only the pages of the PDF I'd like to crop and use options to trim it. I'm waiting for an help in recognizing the most appropriate options to do so.

Werner
  • 603,163
Enlico
  • 2,592
  • Do you want to cut the physical document along the crop marks (off-topic)? Or do you want to remove the crop marks and retain a crop-mark-free PDF? – Werner Jan 11 '16 at 17:54
  • 1
    Try Master PDF 3, it's free if you use it with noncommercial purposes. It allows you to modify PDFs in pretty much any way, doing what you ask for should be a piece of cake. – Alfredo Hernández Jan 11 '16 at 18:22
  • I believe pdfpages has a crop option. After all, it is based on \includegraphics. – John Kormylo Jan 11 '16 at 20:06
  • @Werner, I want to cut the digital document (not the hard copy, since could use scissors :P) along the crop marks. If this is OT, where should I post this question? – Enlico Jan 12 '16 at 09:03
  • 1
    @EnricoMariaDeAngelis: This is possible with pdfpages. – Werner Jan 12 '16 at 15:01
  • Oh, this is a very useful package. I just don't understand how to cut the margins. I'm trying with \includepdf with the trim option which should be passed to \includegraphics, but but it seems to me that the aspect ratio is fixed. I tried with the relative option, but it didn't work. I give you a link to a page of the document which is all white except for crop marks. Can you tell me the option (possibly the most appropriate ones) I should use? – Enlico Jan 12 '16 at 15:36
  • 1
    But note with pdfpages all kinds of links will get lost. Have a look at jPDF Tweak (written in Java), by Michael Schierl. – Javier Bezos Jan 15 '16 at 15:18
  • I know; fortunately this poses no problem if the target is to print hardcopies. – Enlico Jan 15 '16 at 15:27

3 Answers3

5

The pdfcrop utility is made to crop the white borders from a PDF.

pdfcrop in.pdf out.pdf

If you want to remove a little MORE so that the crop marks are also removed, then use the --margins option. Providing a negative margin value will cause a crop of some of your content. The margin value unit is bp. Play with the negative value to remove your tick marks and nothing else.

pdfcrop --margins -10 in.pdf out.pdf 

Edit Using OP's sample PDF follows...

Your sample PDF file works for me. I used the following command.

pdfcrop --margins -10 --verbose matC.pdf matC_cropped.pdf

This is your original file

enter image description here

And this is the cropped file

enter image description here

The pdfcrop verbose log follows

PDFCROP 1.38, 2012/11/02 - Copyright (c) 2002-2012 by Heiko Oberdiek.
* PDF header: %PDF-1.5
* Running ghostscript for BoundingBox calculation ...
GPL Ghostscript 9.04 (2011-08-05)
Copyright (C) 2011 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 1.
Page 1
%%BoundingBox: 3 3 205 205
* Page 1: 3 3 205 205
%%HiResBoundingBox: 3.667289 3.061336 204.622728 204.016705
* Running pdfTeX ...
This is pdfTeX, Version 3.14159265-2.6-1.40.16 (MiKTeX 2.9 64-bit)
entering extended mode
(tmp-pdfcrop-3248.tex [1 <./matC.pdf>] )
Output written on tmp-pdfcrop-3248.pdf (1 page, 24335 bytes).
Transcript written on tmp-pdfcrop-3248.log.
==> 1 page written on `matC_cropped.pdf'.

As you see, pdfcrop used ghostscript. Perhaps your ghostscript has an issue.

James
  • 4,587
  • 1
  • 12
  • 27
  • This doesn't work for me. I mean the output file is exactly the same as the input one. – Enlico Jan 12 '16 at 09:03
  • @EnricoMariaDeAngelis: pdfcrop will only detect white margins. Perhaps you have a background color or the pdf is a scan with random non-white dots in the background? Have you tried the command with the --margins option? That should work with or without a white background. Try increasing the --margins number to -100 and see if there is a noticeable change. If not, are there any error messages output by pdfcrop? – James Jan 12 '16 at 12:42
  • No, it's not a scan, nor it has background color. I tried increasing the number to -100, but it didn't work. No errors, just output coincides with input. – Enlico Jan 12 '16 at 13:28
  • @EnricoMariaDeAngelis: Maybe you could try the commands on another PDF to see if the tool is working in the general case. It's always worked for me. I don't know enough about pdfcrop to understand why else it might fail. If you want to provide a link to your PDF file I would be willing to try it on my computer. – James Jan 12 '16 at 13:39
  • I cannot broadcast the material, but I can provide you a link to a pdf image (the outcome of an externalized tikzpicture) which has white margins that I can't eliminate by means of pdfcrop – Enlico Jan 12 '16 at 15:04
  • @EnricoMariaDeAngelis: See my edited answer for how pdfcrop works with your sample file. – James Jan 12 '16 at 15:45
  • I ran pdfcrop --margins -10 --verbose matC.pdf matC_cropped.pdf from command line, but it didn't work. – Enlico Jan 12 '16 at 15:57
  • I guess if you want to pursue it further, you'll need to compare your log to the one I posted above and let us know the differences. – James Jan 12 '16 at 16:01
  • Ok. Where is the log file located? Oh, if you look at my own comment under the question, you can use the link to a void page of the document I'm talking about – Enlico Jan 12 '16 at 16:02
  • The log is the text written in your command line window as the program is running. I just ran pdfcrop on your provacrop.pdf and it cropped just fine. – James Jan 12 '16 at 16:16
3

I finally solved the problem using the option fitpaper=true (manually setting the trim option).

\documentclass{article}
\usepackage{pdfpages}
\begin{document}
\includepdf[pages={2-32},trim=2.9cm 3.5cm 2.9cm 3.5cm,fitpaper=true]{Chapter05.pdf}            
\end{document}

EDIT: If I think to non LaTeX solutions, briss comes up to my mind.

Enlico
  • 2,592
0

One option would be to iterate over all the pages in your document with crop marks, and each page is trimmed and clipped to remove the crop marks.

First step is to obtain the number of pages to include. For that, see Get number of pages of external PDF.

Second is we iterate over the number of pages sequentially (using multido). At each page, we create a new completely blank page in your document (using \newpage \thispagestyle{empty} \mbox{}) and insert a page from the PDF as an overlay using eso-pic). The overlay is placed in the ForeGround on that specific page only (due to *), with the appropriate horizontal and vertical shifts that we removed (trimmed from the original page image).

enter image description here

\documentclass{article}
\usepackage{multido,geometry,eso-pic,graphicx}
\usepackage{pdfpages}
\geometry{paper=a4paper}

\begin{document}

\includepdf{provacrop}% For reference

% https://tex.stackexchange.com/q/198091/5764
\pdfximage{provacrop.pdf}%
\edef\numberofpages{\the\pdflastximagepages}%

\multido{\i=1+1}{\numberofpages}{%
  \newpage% Start a new page
  \thispagestyle{empty}% No header/footer
  \mbox{}% Just to put something on this blank page
  \edef\x{%
    \noexpand\AddToShipoutPictureFG*{%
      \noexpand\AtPageLowerLeft{%
        \noexpand\hspace{20mm}% Horizontal shift
        \noexpand\raisebox{25mm}{% Vertical shift
          \noexpand\includegraphics[trim=20mm 25mm 20mm 25mm,clip,page=\i]{provacrop}}%
    }%
  }}\x%
}

\end{document}

Above I've trimmed 20mm horizontally and 25mm vertically just to show how it affects the output. You could play around with these lengths until the crop marks disappear.

The use of \edef\x{..}\x is to ensure the proper choice for page=\i - \i has to be completely expanded in order to be processed correctly by \includegraphics.

Werner
  • 603,163
  • Copied the code, I get exactly what you got, but this is not what I want to do. What I want to do digitally is exactly what I would do manually with scissors. The difference is that, doing it manually, I would get sheets smaller than A4, whereas if I do it digitally, I can print the page on a A4 paper. – Enlico Jan 13 '16 at 13:43
  • In other words, I don't want to remove cut marks; I want to cut out white margins as indicated by marks. – Enlico Jan 13 '16 at 15:37
  • @EnricoMariaDeAngelis: I honestly have no idea what that means. – Werner Jan 13 '16 at 17:02
  • What would you do if you had to print a pdf document which has wide white margins and crop marks, using a home printer? I don't think you would print it as it is; indeed you would crop each page cutting out the white margins (crop marks would be cut out too, since they are in the outer part, the part which has to be cut out). I would you accomplish this task? – Enlico Jan 14 '16 at 07:51
  • @EnricoMariaDeAngelis: Okay, so you want to remove the crop marks, but also zoom the page so you could fill what is printed in the page. Is that it? – Werner Jan 14 '16 at 08:22
  • I'm so sorry for my english, which could be an important aspect of the misunderstanding. Yes, I think you got the point. Just to be as clear as I can, I write it in other words: given this pdf document, I'd like to obtain another one containing only the part surrounded by the four crop marks. (Even when the pdf document is made up of more pages.) – Enlico Jan 14 '16 at 14:30