Set the maximum page size of a PDF canvas

I have a PDF document in which all page sizes are different. I want to adjust the size of each page (aka canvas) to the maximum width and maximum height found in the document, and then center it.

I'm used to pdftk and Ghostscript , but I can consider some other FOSS tools if this is better.

How to do it? Thanks in advance.

+4
source share
1 answer

I made my part of pdfjam scripts, so I decided that I would try.

script, pdfinfo pdfjam (: pdflatex, , ):

#!/bin/bash

pdf=$1

nb_pages=$(pdfinfo "$pdf" | grep ^Pages: | cut -f2 -d:)
echo "Found $nb_pages pages in document"

# Get page sizes as string of width:height values in points (ie "2380:3368 3368:2380 1684:2380 ...")
page_sizes=$(seq $nb_pages | while read p; do pdfinfo -f $p -l $p "$pdf" | grep -e '^Page.* size:' | awk '{print $4,$6}'; done)
echo "Page sizes: $page_sizes"

max_width=$(echo $page_sizes | tr ' ' '\n' | cut -f 1 -d: | sort -n | tail -n 1)
echo "Max width: $max_width"

max_height=$(echo $page_sizes | tr ' ' '\n' | cut -f 2 -d: | sort -n | tail -n 1)
echo "Max height: $max_height"

# Run pdfjam on source pdf and set page size, it will center each page
set -x
pdfjam --suffix fixed "$pdf" --papersize "{${max_width}pt,${max_height}pt}"

( "output.pdf", ), ( , ) , --papersize. pdfjam, ( ) .

, .

0

Source: https://habr.com/ru/post/1676539/


All Articles