Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
2  
Do not use the imagemagick tools like convert. They rasterize the output and degrade the quality. –  Marco Jul 27 '12 at 8:50
    
@Marco Thanks for the tip! Do you have a suggestion for an alternative? –  Dalker Jul 27 '12 at 16:49
add comment

4 Answers 4

up vote 1 down vote accepted

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)
share|improve this answer
    
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
add comment

Use PDFjam to do this.

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

share|improve this answer
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
add comment

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: 
# http://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.

share|improve this answer
add comment

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

share|improve this answer
1  
What I actually want to do is the opposite of psnup: instead of putting several pages into one, I need to split one page into two. –  Dalker Jul 27 '12 at 16:45
    
Sorry, I misunderstood it then. psutils has psselect for that. –  klapaucius Jul 28 '12 at 8:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.