Thanks, I tried pdfScale.sh
and cpdf
, and cpdf
works for me.
cpdf
will stretch the cover and content to fill the entire page without extra white space left.
Here is the command, you need to calculate the scale ratio when use cpdf
with the option -scale-page
cpdf -scale-page "x_ratio_not_size y_ratio_not_size" input.pdf -o output.pdf
I use a fish function cpdfscale
which depends on pdfinfo
and cpdf
to convert pdf files for my apple devices.
Here is the cpdfscale.fish
source code:
function cpdfscale
# Get pdf file origin size
set -l dim_x (pdfinfo $argv[3] | grep -a "Page size" | cut -d\: -f2 | cut -dx -f1 | sed 's/^[ \t]*//')
set -l dim_y (pdfinfo $argv[3] | grep -a "Page size" | cut -d\: -f2 | cut -dx -f2 | cut -d' ' -f2 | sed 's/^[ \t]*//')
echo Origin Page Size\t :\t $dim_x x $dim_y pts
echo Scaled Page Size\t :\t $argv[1] x $argv[2] pts
# Calc scale ratio
set -l sx (math $argv[1] / $dim_x)
set -l sy (math $argv[2] / $dim_y)
echo Scaled Page Ratio\t :\t $sx x $sy
# Set output file and convert
if test (count $argv) -gt 3
echo Scaled Output File\t :\t $argv[4]
cpdf -scale-page "$sx $sy" $argv[3] -o $argv[4] &> /dev/null
else
set -l outfile (echo $argv[1]x$argv[2] - (basename $argv[3] .pdf).pdf)
echo Scaled Output File\t :\t $outfile
cpdf -scale-page "$sx $sy" $argv[3] -o $outfile &> /dev/null
end
echo "Scale finished"
end
Usage:
cpdfscale x_size_in_pts y_size_in_pts input.pdf [output.pdf]
.
if the output file is not specified, a new file name with origin name
and new file page dimensions ${x_size_in_pts}x${y_size_in_pts} - ${origin_name}.pdf
will be used.
The following command convert any pdf file for my iPad Air4 which has a screen with size 1640 x 2360 pts.
cpdfscale 1640 2360 origin.pdf scaled.pdf
The core command to get my work done is:
cpdf -scale-page "3.253968 4.173453" origin.pdf -o scaled.pdf
Here is the output:
>=> cpdfscale 1640 2360 origin.pdf
Origin Page Size : 504 x 565.479 pts
Scaled Page Size : 1640 x 2360 pts
Scaled Page Ratio : 3.253968 x 4.173453
Scaled Output File : 1640x2360 - origin.pdf
Scale finished
>=> cpdfscale 1640 2360 origin.pdf scaled.pdf
Origin Page Size : 504 x 565.479 pts
Scaled Page Size : 1640 x 2360 pts
Scaled Page Ratio : 3.253968 x 4.173453
Scaled Output File : scaled.pdf
Scale finished