I want to split a PDF page because it scanned two page at the time and I found this useful command:

convert in.pdf -crop 50%x0 +repage -density 400 out.pdf

But now I want this command to skip spliting some pages and use them in the final repage result as they are.

Are there any command or a way to do so?

1 Answer 1

  1. I hope you set the -density correct, so that you do not degrade your image during the re-rasterising. However, I think -density 400 should come before pdf.in to take an effect.

  2. I hope that your pdf file from the corridor scanner is safe, in particular that it is not a Postscript file internally. Also I hope that you have a safe version of GS (which is called by IM for pdf/ps/... conversions.) link, link. (gs --version ≥9.24)

  3. Anyway, with regard to the previous two points, for the scanner origniated pdf files I would recommend to start by pdfimages program to extract the scanned pages. Something like

   pdfimages -list in.pdf        # show info

   rm temporary*                 # remove temporary files
   rm DOcrop*                    # remove our option files

   pdfimages -all in.pdf temporary    # -all for natural (original) format    
   # make your choices; can be done manually by  touch  program
   for x in termporary*; do
        gopen "$x"            # view the file
        echo "File $x: <Enter> for crop, <Ctrl-D> for keep"
        read  &&    touch DOcrop-"$x"
   for x in termporary*; do
        [ -e DOcrop-"$x" ] && mogrify -crop 50%x0 +repage "$x"

   convert temporary*  out.pdf      # some options?
  1. You can use convert pdf.in[0-1,7] ... to use just the specified pages. See 7.

  2. You can use tools like pdftk, qpdf, pdfselect+pdfunify to select and/or reorganise the pages

  3. For pdfs with vector graphics or text (not good for scanned pags) one can use pdfcrop which uses TeX

  4. convert can have a long command line. It seems you will need to use stack operations if you go this way, something like convert in.pdf[0-9] \( in.pdf[10] -crop ... \) ... to make first ten pages non-changed, and eleventh page cropped. Without \( \), cropping operation would be applied on all preceding pages.

  5. IM and GM have scripting tools, which I do not konw.

  • Thank you for the answer, I will try it as soon as possible.
    – malloc
    Commented Sep 10, 2023 at 3:34

You must log in to answer this question.

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