Conversion ToolsHow to convert from a 2nup pdf to a single page one

Information and discussion about output converters related to LaTeX (e.g. dvips, ps2pdf, ...)
Post Reply
migf
Posts: 20
Joined: Mon Feb 18, 2013 2:33 pm

How to convert from a 2nup pdf to a single page one

Post by migf »

Hello,

I have a pdf file with 2 nup sub-pages per landscape page and I need to convert this to an upright document whose pages are the sub-pages. I tried to use pstops but I could not make out how to do this. I can also use the other psutils, poppler, pdfjam, pdftk and Texlive, And of course I can use Gimp or something like it to make the separation by hand, but this will be too much work,

Any help will be very welcome!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
migf
Posts: 20
Joined: Mon Feb 18, 2013 2:33 pm

How to convert from a 2nup pdf to a single page one

Post by migf »

It seems the problem I am dealing with has no known solution, so I offer a poor man's one:

- use pdftk, or any similar tool to create a pdf file for each page in the original document

Code: Select all

 mkdir temp ; cd temp
 pdftk  burst ../original.pdf
- for each page in pg001.pdf .... convert from pdf to png or tiff or some other raster format accepted by ImageMagick, and then create a file with the subpages:

Code: Select all

 convert-im6.q16 pg_0001.pdf pg1.png
 convert-im6.q16 pg1.png -crop 2x1@ +repage pc1_%d.png
where 2x1@ means that there are 2 subpages in 2nup format and pc1_%d.png gives the pattern for the resulting filenames

- now convert each subpage file to pdf

Code: Select all

 convert-im6.q16 pc1_0.png pc1_0.pdf
It is clear that the conversion from pdf to a raster format implies a quality loss that cannot be avoided if there are no pdf nor ps tools for doing the job.
migf
Posts: 20
Joined: Mon Feb 18, 2013 2:33 pm

How to convert from a 2nup pdf to a single page one

Post by migf »

Here is an upgrade to my previous poor man's solution that will be of use if one only wants to process images in the original pdf, what will be the case if it contains a scanned document.

Instead of using pdftk to get the pages and then converting them to png, pdfimages should be used to get the images as they are in the pdf, keeping its resolution and format (png, jpeg, ...):

Code: Select all

pdfimages -f 1 -l 4 -all ../original.pdf pg
where -f and -l give the numbers of the first and last pages, -all keeps the original format, and pg the prefix for the resulting files,

Then follows the cropping of the subpages as before:

Code: Select all

convert-im6.q16 pg1.png -crop 2x1@ +repage pc1_%d.png
convert-im6.q16 pc1_0.png pc1_0.pdf
...
As in my case I am dealing with scanned documents no quality loss is to be expected and I will mark this as solved.
Post Reply