5

I'm having trouble using convert to do the following:

I have a bunch of single-page pdf files whose geometry corresponds to a landscape A4 sheet. The actual content is visually split in 2 pages. What I've been trying to do with each of these files, is basically: resize to A3, actually split vertically in the middle to get two pages (I've tried convert's crop unsuccesfully), then re-assemble as a 2-page pdf file made of 2 A4 portrait-oriented pages.

The final content should be the original content resized by a factor sqrt(2)

[  ] -> [    ]  ->  [ | ]
        [    ]      [ | ]
 A4       A3         2xA4
lands.   lands.     portrait

The whole purpose of this is to be able to print the resized content as 2 portrait A4 sheets instead of 1 landscape A4, but actually creating new pdf files would be better than printing directly, as they can then be reprinted anytime and shared with other people who'll then be able to print them directly as intended as well.

Dalker
  • 1,622

5 Answers5

3

Here's a variant of un2up, which uses Python with the pyPdf library. Note that you need at least version 1.13 (prior versions did not support scaling). Untested.

#!/usr/bin/env python
import copy, math, sys
from pyPdf import PdfFileWriter, PdfFileReader
input = PdfFileReader(sys.stdin)
output = PdfFileWriter()
for p in [input.getPage(i) for i in range(0,input.getNumPages())]:
    p.scaleBy(math.sqrt(2))
    q = copy.copy(p)
    (w, h) = p.mediaBox.upperRight
    p.mediaBox.upperRight = (w/2, h)
    q.mediaBox.upperLeft = (w/2, h)
    output.addPage(p)
    output.addPage(q)
output.write(sys.stdout)
  • This worked when commenting out p.scaleBy(math.sqrt(2)), which for some reason produced a blank output pdf. Fortunately, evince is smart enough to print the resulting split pdf in full A4 anyway, so this did answer my question and avoids using any explicit geometry, which is a really good thing. Note on ArchLinux: first line must be explicitly #!/usr/bin/env python2 as python3 is the default. – Dalker Jul 31 '12 at 20:01
2

Use PDFjam to do this.

See: https://superuser.com/questions/246092/how-to-convert-a-1-page-pdf-to-a-2-page-per-sheet-pdf

Stone
  • 545
  • 1
    From the man page and --help of pdfjam, I understand how to join two pdf files/pages/sheets into one. But I want to do the opposite: split one page into two. Is that actually possible? – Dalker Jul 27 '12 at 16:48
  • Folllowing a link from your link, I found a way to do it. I'm going to add it as a separate answer for clarity. – Dalker Jul 27 '12 at 17:22
2

I managed to solve my original problem using a gs solution based on the answer to this question on superuser.com, found following a link within another Q/A refered to in @Stone's answer to the present question.

Here's a way it can be done, put into a script:

#!/bin/bash
################################################################
# Make two portrait A4 sheets out of one landscape A4 sheet, by
# splitting and resizing adequately
################################################################
# solution based on: 
# https://superuser.com/questions/235074/freeware-to-split-a-pdfs-pages-down-the-middle/235401#235401
################################################################
IN=$1
OUT=$2
TMPLEFT=/tmp/left.pdf
TMPRIGHT=/tmp/right.pdf

# left side
gs -o $TMPLEFT -sDEVICE=pdfwrite -g5955x8420 -c "<</PageOffset [0 0]>>" setpagedevice -f $IN
# right side
gs -o $TMPRIGHT -sDEVICE=pdfwrite -g5955x8420 -c "<</PageOffset [-595.5 0]>>" setpagedevice -f $IN
# join
pdfunite $TMPLEFT $TMPRIGHT $OUT

I still think there should be an easier way, but this works and avoids ImageMagick convert's shortcomings.

Dalker
  • 1,622
0

For a few 11x17 to 8.5x11 pages it is simple using the Adobe Acrobat Pro tools.

Open original file,
Set to landscape view.
Save file with another name (say something like "Original v2p1.pdf)
Select "Advanced" tab
Select "Print Production"
Select "Crop Pages"
Crop half the page from the right or left side.
Save file ("Original v2p1.pdf). You now have page 1.
Open "Original.pdf, the original.
Save file with another associated name (page 2 might be "Original v2p2.pdf)
Crop half the page from the other side.
Save file ("Original v2p2.pdf). You now have page 2.

PersianGulf
  • 10,850
0

I like psnup which is part of the psutils. Here is a HOWTO to accomplish what you are looking for:

http://www.peppertop.com/blog/?p=35