Page 1 of 2
PDF is too small (in cm)
Posted: 2014-11-14T01:43:16-07:00
by akapuma
Hello,
I want to convert a postscript file (.PS) into a PDF file. I'm using the following command line:
Code: Select all
convert -limit memory 1GiB -limit map 2GiB -define registry:temporary-path="c:\tmp" -density 300x300 -page A4 -colors 2 +dither -monochrome -compress group4 input.ps output.pdf
The problem is, that the size of the pdf is 5,04cm x 7,13cm (reported by Acrobat reader and PDF XChange Viewer). Expected is 21cm x 29,7cm.
For testing, I changed the output from PDF to TIF:
Code: Select all
convert -limit memory 1GiB -limit map 2GiB -define registry:temporary-path="c:\tmp" -density 300x300 -page A4 -colors 2 +dither -monochrome -compress group4 input.ps output.tif
The resulting picture is 2479 pixels x 3508 pixels. This is correct for A4 size at 300 dpi.
What is the cause? I'm using ImageMagick 6.8.9-9 Q16 x86 2014-10-19.
Best regards
akapuma
Re: PDF is too small (in cm)
Posted: 2014-11-14T02:04:09-07:00
by snibgo
Code: Select all
convert -limit memory 1GiB -limit map 2GiB -define registry:temporary-path="c:\tmp" -density 300x300 -page A4 -colors 2 +dither -monochrome -compress group4 input.ps output.pdf
The syntax is wrong. It should be: input-file, processing, output file, like this:
Code: Select all
convert -limit memory 1GiB -limit map 2GiB -define registry:temporary-path="c:\tmp" input.ps -density 300x300 -page A4 -colors 2 +dither -monochrome -compress group4 output.pdf
Remove "-density 300x300". I think the size will then be A4.
Re: PDF is too small (in cm)
Posted: 2014-11-14T03:52:03-07:00
by akapuma
The syntax is wrong. It should be: input-file, processing, output file, like this:
In this case, the result is wrong. For testing, you can use this test picture:
http://anders.geekhouse.no/Testpage/
Remove "-density 300x300". I think the size will then be A4.
Yes, this works, output is A4.
Problem: output is only 595x842 pixels = 72dpi.
I want to have 2479x3508 pixels = 300dpi
Best regards
akapuma
Re: PDF is too small (in cm)
Posted: 2014-11-14T04:22:03-07:00
by pipitas
Hmm...
Why do you even use ImageMagick for this job in the first place?!?
IM cannot handle PS input directly. It employs Ghostscript as its delegate to convert the PS into a raster format it understands. You can observe this yourself by adding
to beginning of the commandline. It will show you a line like this:
Code: Select all
[ghostscript library] -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 \
-dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g192x192 \
"-sOutputFile=/tmp/magick-18532WfuSEjmDC1iH%d" "-f/tmp/magick-18532ERyUj24PgJBq" "-f/tmp/magick-185327SZZPqvlFLP9"
So only after Ghostscript converted the PDF page to a PNG with an alpha channel ImageMagick will ever get hold of the result. When IM produces the output PDF, its pages will
only contain raster data where before there were fonts and vector graphics.
Is this what you want?
If ImageMagick's convert does work at all, it means you have Ghostscript installed on your system anyway. So you could also go from PS -> PDF directly:
Code: Select all
gswin64c.exe -o output.pdf -sDEVICE=pdfwrite testpage.ps
Is the reason for using ImageMagick:
you want to remove the colors from the PS and get a grayscale PDF? This can be achieved with using Ghostscript directly too:
Code: Select all
gswin64c.exe ^
-o grayscale.pdf ^
-sDEVICE=pdfwrite ^
-sColorConversionStrategy=Gray ^
-sProcessColorModel=DeviceGray ^
-dOverrideICC ^
-dCompatibilityLevel=1.4 ^
c:/path/to/input.ps-or-pdf
Re: PDF is too small (in cm)
Posted: 2014-11-14T07:55:07-07:00
by akapuma
Why do you even use ImageMagick for this job in the first place?!?
I want to have a PDF with the following requirements:
- no fonts, no vector graphics, bitmap graphics only
- Because the size of a bitmap is very high, a good compression is needed. Very effective is fax compression group 4.
- The fax compression needs a monochrome picture (1 bit per pixel).
- The monochrome compression should be done without dithering (looks better).
Your hint to gswin is very interesting! I will reed the option in the next days. Thank you.
Best regards
akapuma
Re: PDF is too small (in cm)
Posted: 2014-11-14T10:22:26-07:00
by pipitas
To convert an A4 (color) PostScript into a grayscale PDF where each page contains only bitmaps with TIFF G4 (a.k.a. "fax") compression, and to have 300 ppi resolution per page, use these 2 commands:
Code: Select all
gs -o testpage.tif -sDEVICE=tiffg4 -r300 testpage.ps
tiff2pdf -p A4 -F testpage.tif > testpage.tif.pdf
If your final PDF should contain metadata for creator software, author, title, subject and keywords, insert the following parameters into the second command as needed:
Code: Select all
-c "Creator software name"
-a "Author name"
-t "Document title"
-s "Document subject"
-k "Keyword1, Keyword2, Keyword3, ..."
To check the embedded images (their width, height, resolutions) use this command:
pdfimages -list testpage.tif.pdf
You should see:
Code: Select all
page num type width height color comp bpc enc interp object ID x-ppi y-ppi size ratio
--------------------------------------------------------------------------------------------
1 0 image 2550 3300 gray 1 1 ccitt no 7 0 309 309 358K 35%
To control exactly the number of pixels in width and height of the TIFF, change the first command (Ghostscript):
Code: Select all
gs -o testpage.tif -sDEVICE=tiffg4 -g2479x3508 testpage.ps
Re: PDF is too small (in cm)
Posted: 2014-11-14T10:53:50-07:00
by snibgo
That image is square. If you want it to fill an A4 page, it will need stretching.
With IM, you can use "-density"
before the input file to get a certain number of pixels. Then use another "-density"
after the input file to change the density without resampling the pixels.
Re: PDF is too small (in cm)
Posted: 2014-11-14T11:50:49-07:00
by pipitas
No, it's not square. It
IS A4. Not sure what you base your statement about its squareness on.
According to Ghostscript, it's real BoundingBox (that is, the area, where ink would be deposited by a printer) is this:
Code: Select all
gs -q -o - -sDEVICE=bbox testpage.ps
%%BoundingBox: -1 -1 596 843
%%HiResBoundingBox: -0.008930 -0.008930 595.008966 842.008966
According to some (unofficial) PostScript standard if a size specification deviates by +5pt or -5pt from the print device's supported page size, it should still be deemed valid. (This originates from the PostScript Language and Reference, 3rd Ed, where the exact behaviour of a device is controlled by the
/Policies <</PageSize N>> dictionary for cases where a requested media size cannot be matched exactly, but is within the -5pt -- +5pt range...)
Re: PDF is too small (in cm)
Posted: 2014-11-14T12:18:27-07:00
by fmw42
When I do this:
I get a center cropped region of the original that is square 192x192. I suspect that is what snibgo is suggesting by square.
IM see this for verbose information
Image: testpage.ps
Format: PS (PostScript)
Mime type: application/postscript
Class: DirectClass
Geometry: 192x192+0+0
Resolution: 72x72
Print size: 2.66667x2.66667
Units: Undefined
Type: TrueColorAlpha
Endianess: Undefined
Colorspace: sRGB
Depth: 16/8-bit
Page geometry: 192x192+0+0
You may have to use ghostscript standalone to avoid this cropping. I do not know where in the ps file data it says to crop.
Re: PDF is too small (in cm)
Posted: 2014-11-14T12:25:35-07:00
by snibgo
pipitas wrote:No, it's not square. It IS A4. Not sure what you base your statement about its squareness on.
Ah, thanks. I was looking at the line "%%BoundingBox: 210 285 402 477". But I don't know much about PS.
Re: PDF is too small (in cm)
Posted: 2014-11-14T16:54:48-07:00
by pipitas
The %%BoundingBox statement you found in the testpage.ps was the one coming from Einstein's picture, which is embedded in the main PS as an Encapsulated PostScript file. It is not at all valid and irrelevant for the overall main PS.
Re: PDF is too small (in cm)
Posted: 2014-11-14T17:11:09-07:00
by pipitas
fmw42 wrote:IM see this for verbose information
Image: testpage.ps
Format: PS (PostScript)
Mime type: application/postscript
Class: DirectClass
Geometry: 192x192+0+0
Resolution: 72x72
Print size: 2.66667x2.66667
Units: Undefined
Type: TrueColorAlpha
Endianess: Undefined
Colorspace: sRGB
Depth: 16/8-bit
Page geometry: 192x192+0+0
Funnily,
my version of IM reports this PS as a
PNG file!
Code: Select all
identify -verbose testpage.ps | head -n 12
Image: testpage.ps
Format: PNG (Portable Network Graphics)
Mime type: image/png
Class: DirectClass
Geometry: 192x192+0+0
Resolution: 72x72
Print size: 2.66667x2.66667
Units: Undefined
Type: TrueColorAlpha
Endianess: Undefined
Colorspace: sRGB
Depth: 16/8-bit
Something is seriously wrong with IM here.
It seems that it parses the entire file for occurences of
'%%BoundingBox', takes the values found there (in this case:
'210 285 402 477') and calculates from it the 'geometry' it reports.
This is plainly wrong. This procedure is only ever valid for a standalone EPS file, but never for a general PS file which may contain EPS files used as page elements (like here).
Re: PDF is too small (in cm)
Posted: 2014-11-14T20:06:20-07:00
by fmw42
Funnily, my version of IM reports this PS as a PNG file!
I am using IM 6.8.9.10 Q16 Mac OSX.
Perhaps it has to do with the file on your image hosting server or the way it gets downloaded. If you download your file from the hosting service, do you still get PNG?
Re: PDF is too small (in cm)
Posted: 2014-11-15T03:34:57-07:00
by pipitas
fmw42 wrote:Funnily, my version of IM reports this PS as a PNG file!
6.8.9-8 Q16 Mac OSX here, installed via MacPorts.
Re: PDF is too small (in cm)
Posted: 2014-11-15T10:50:21-07:00
by fmw42
pipitas wrote:fmw42 wrote:Funnily, my version of IM reports this PS as a PNG file!
6.8.9-8 Q16 Mac OSX here, installed via MacPorts.
I install my delegates from MacPorts, but install IM from source manually. see
viewtopic.php?f=1&t=21502&p=88202&hilit ... rts#p88202