This can be done using pdftk.
$ <in>pdftk form.pdf dump_data_fields > form_fields.txt</in> $ <in>vim form_fields.txt</in> [...] $ # XXX generate data.fdf from form_fields.txt; see http://www.myown1.com/linux/pdf_formfill.shtml $ <in>pdftk form.pdf fill_form data.fdf output data.pdf</in>
$ <in>podofopdfinfo P in.pdf | grep MediaBox</in> MediaBox: [ 0.000000 0.000000 841.680000 595.080000 ] $ <in>podofobox in.pdf cropped.pdf crop 42050.0000 000.0000 84168.0000 59508.0000</in> # Note: dimensions are in centi-pts; and the coordinates start from the bottom-right
$ <in>gs -o cropped.pdf -sDEVICE=pdfwrite -c "[/CropBox [0 0 280.59 419.52] /PAGES pdfmark" -f input.pdf</in>
The unit of 'CropBox
' (and 'MediaBox
') are expressed in an unclear (to me) unit. In this example, 280.59 was 99mm.
Using Ghostscript unfortunately scrapes the metadata.
Once again, PDFTK comes to the rescue.
$ <in>pdftk input.pdf dump_data | pdftk cropped.pdf update_info - output cropped2.pdf</in>
For example, 2xA5 on one A4 page. As seen here, this requires a Perl script.
#!/usr/bin/env perl # Original found at [0] # [0] http://fitzcarraldoblog.wordpress.com/2013/11/09/split-an-a4-pdf-file-into-two-a5-pdf-files/ use strict; use warnings; use PDF::API2; my $filename = shift || 'test.pdf'; my $oldpdf = PDF::API2->open($filename); my $newpdf = PDF::API2->new; for my $page_nb (1..$oldpdf->pages) { my ($page, @cropdata); $page = $newpdf->importpage($oldpdf, $page_nb); @cropdata = $page->get_mediabox; $cropdata[2] /= 2; $page->cropbox(@cropdata); $page->trimbox(@cropdata); $page->mediabox(@cropdata); $page = $newpdf->importpage($oldpdf, $page_nb); @cropdata = $page->get_mediabox; $cropdata[0] = $cropdata[2] / 2; $page->cropbox(@cropdata); $page->trimbox(@cropdata); $page->mediabox(@cropdata); } (my $newfilename = $filename) =~ s/(.*)\.(\w+)$/$1.split.$2/; $newpdf->saveas($newfilename); __END__
This script is trivial to use.
$ <in>./split_pdf_A4_to_A5.pl in.pdf</in>
It will create a 'in.split.pdf
' file.
Based on this.
$ <in>pdf2ps in.pdf a.ps</in> $ <in>psbook a.ps b.ps</in> $ <in>ps2pdf b.ps c.pdf</in> $ <in>pdfnup c.pdf --nup 2x1</in>
The output is 'c-nup.pdf
'.
As seen here.
This is trivial with pdftk and a blank page of the right size.
$ <in>pdftk A=in.pdf B=blank.pdf cat A1 B A2-end output out.pdf</in>