Outils pour utilisateurs

Outils du site

Panneau latéral




Ham Radio






PDF manipulation

Fill PDF form with an FDF file

This can be done using pdftk.

$ pdftk form.pdf dump_data_fields > form_fields.txt
$ vim form_fields.txt
$ # XXX generate data.fdf from form_fields.txt; see http://www.myown1.com/linux/pdf_formfill.shtml
$ pdftk form.pdf fill_form data.fdf output data.pdf

Crop a PDF file

Using PoDoFo

As adapted from here. PoDoFo.

$ podofopdfinfo P in.pdf  | grep MediaBox
        MediaBox: [ 0.000000 0.000000 841.680000 595.080000 ]
$ podofobox in.pdf cropped.pdf crop 42050.0000 000.0000 84168.0000 59508.0000 # Note: dimensions are in centi-pts; and the coordinates start from the bottom-right

Using GhostScript

$ gs -o cropped.pdf -sDEVICE=pdfwrite -c "[/CropBox [0 0 280.59 419.52] /PAGES pdfmark" -f input.pdf

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.

Copy PDF metadata

Once again, PDFTK comes to the rescue.

$ pdftk input.pdf dump_data  | pdftk cropped.pdf update_info - output cropped2.pdf

Split multi-page-on-one-page scans

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 = $newpdf->importpage($oldpdf, $page_nb);
	@cropdata = $page->get_mediabox;
	$cropdata[0] = $cropdata[2] / 2;
(my $newfilename = $filename) =~ s/(.*)\.(\w+)$/$1.split.$2/;

This script is trivial to use.

$ ./split_pdf_A4_to_A5.pl in.pdf

It will create a 'in.split.pdf' file.

Create a Booklet

Based on this.

$ pdf2ps in.pdf a.ps
$ psbook a.ps b.ps
$ ps2pdf b.ps c.pdf
$ pdfnup c.pdf --nup 2x1

The output is 'c-nup.pdf'.

Insert a Blank Page

As seen here.

This is trivial with pdftk and a blank page of the right size.

$ pdftk A=in.pdf B=blank.pdf cat A1 B A2-end output out.pdf

Create a Blank Page

$ echo "" | ps2pdf -sPAPERSIZE=a5 - blank.pdf

Custom PAPERSIZE dimensions can hakishly be added to /usr/share/ghostscript/${GS_VER}/Resource/Init/gs_statd.ps

tips/pdf.txt · Dernière modification: 2016-07-21 03:25 par shtrom