Reputation: 904
I try to convert PDF to PNG, but ouput image is always A4, however the source PDF is very huge. Here are my commands:
-dNOPAUSE ^
-dBATCH ^
-dSAFER ^
-sDEVICE=png16m ^
-dFirstPage=1 ^
-sOutputFile="D:\PDF.png" ^
"D:\PDF.pdf" ^
-sPAPERSIZE=a1
I tried several options (-r, -g, -sDEFAULTPAPERSIZE), but none worked.
How can I force the output image dimensions?
P.S: my PDF file
Upvotes: 5
Views: 7794
Reputation: 4093
function pdf2png-mutool() {
#: "mutool draw [options] file [pages]"
# pages: Comma separated list of page numbers and ranges (for example: 1,5,10-15,20-N), where
# the character N denotes the last page. If no pages are specified, then all pages
# will be included.
local i="$1"
local out="${pdf2png_o:-${i:r}_%03d.png}"
[[ "$out" == *.png ]] || out+='.png'
command mutool draw -o "$out" -F png "$i" "${@[2,-1]}"
#: '`-r 300` to set dpi'
}
Upvotes: 0
Reputation: 90193
Your linked-to PDF file has only 1 page. That means your commandline parameter -dFirstPage=1
doesn't have any influence.
Also, your -sPAPERSIZE=a1
parameter should not be last (it doesn't have any influence here -- so Ghostscript takes the default size from the pagesize of the input PDF, which is A4). Instead it should appear somewhere before the "D:\PDF.pdf"
(which must be last).
It looks like you want a PNG with the size of A1, and your OS is Windows (guessing from the partial commandline you provided)?
Try this instead (it adds -dPDFFitPage=true
to the commandline and puts the arguments into a correct order, while also shortening it a bit using the -o
trick):
gswin32c.exe ^
-o "D:\PDF.png ^
-sDEVICE=png16m ^
-sPAPERSIZE=a1 ^
-dPDFFitPage=true ^
"D:\PDF.pdf"
This should give you a PNG with the size of 1684x2384 pixel at 72dpi (which is the builtin default for all Ghostscript image output, used if no other resolution is specified). For different combinations of resolution and pagesize add your variation of -rXXX
and -gNNNxMMM
(instead of -sPAPERSIZE=a1
) but by all means keep the -dPDFFitPage=true
....
You can also keep the -sPAPERSIZE=a1
and add -r100
or -r36
or -r200
if you want a different resolution only. Be aware that increasing resolution may not improve the image quality compared to the default output of 72dpi. That depends on the resolution of the images that were embedded in the PDF page. But it surely increases the file size...
Upvotes: 5