Imagemagick, Snow Leopard and PDF Conversion - macos

Having difficulties with Imagemagick and Snow Leopard.
Imagemagick was installed using the install script from here here. Everything builds and installs correctly. Imagemagick behave normally for all commands (that I can find) except when trying to convert a PDF. For example,
$ convert my.pdf my.jpg
Segmetation Fault
I thought it may be ghostscript and tried to run the command that Imagegick delegates too (via the -verbose option)
$ convert -verbose spec/fixtures/documents/upload_test_file.pdf test.jpg
"gs" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" "-sOutputFile=/var/folders/Xz/Xz6TDr0DFQaV5J1F7Ndamk+++TM/-Tmp-/magick-4zvJXfSz" "-f/var/folders/Xz/Xz6TDr0DFQaV5J1F7Ndamk+++TM/-Tmp-/magick-O7a9fDyp" "-f/var/folders/Xz/Xz6TDr0DFQaV5J1F7Ndamk+++TM/-Tmp-/magick-rBEzLUsx"
Segmentation fault
$ "gs" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pnmraw" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" "-sOutputFile=my.jpg" "-fmy.pdf"
And it works. It creates the pnmrow file as its supposed to.
I am not sure where to go from here, anyone else seen this or seen it and solved it?

me too.
$ identify issue7.pdf
Segmentation fault
Looks like the imagemagick team is aware of the problem and it should be fixed in version 6.5.5-8.
UPDATE: Actually - The MacPorts package uses the newer version of ImageMagick as of 9/16/09. Try doing a self update and then upgrading php5-imagick.
sudo port selfupdate
sudo port upgrade php5-imagick
This fixed the problem for me.

Related

A ghostscript scipt no longer working: pdfwite needs an output file

I have been using this file for quite some time, today it stopped working:
C:\"Program Files"\gs\gs9.53.2\bin\gswin64 -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dBATCH -dPrinted=false -dPassThroughJPEGImages=false -dDownsampleColorImages=true -dColorImageResolution=400 -dDownsampleGrayImages=true -dGrayImageResolution=400 -dDownsampleMonoImages=true -dMonoImageResolution=400 -dNOPAUSE -dBATCH -sOutputFile=FalterinLenzkirchV2_Compressed.pdf FalterInLenzkirchV2.pdf
I am very surprised; the error message is
'pdfwrite' requires an output file but no file was specified
The output file is there
Since this a batch sript not being changed, I wonder what else has changed which I am not aware of?
"C:/Program Files/gs/gs9.53.2/bin/gswin64c.exe" -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dBATCH -dPrinted=false -dPassThroug hJPEGImages=false -dDownsampleColorImages=true -dColorImageResolution=400 -dDownsampleGrayImages=true -dGrayImageResolution=400 -dDownsampl
eMonoImages=true -dMonoImageResolution=400 -dNOPAUSE -dBATCH -sOutputFile=annots.pdf examples/annots.pdf
WORKSFORME -- Please try with that input file, and if that doesn't work we will need to get your input file.

How should I get UN-rotated JPEG image file from ghostscript?

I am running with crazy issue in ghostscript 9.15.I have two commands for converting PDF to JPEG images,which has difference in height and width only.
Command 1st
-q -dUseCropBox -dBATCH -dDOINTERPOLATE -dMaxBitmap=300000000 -dAlignToPixels=0 -dNOPAUSE -dSAFER -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -dPDFFitPage -dPrinted=false -r144 -g200x200 -sDEVICE=jpeg -dJPEGQ=100 -sOutputFile="output.jpg" "input.pdf" -c quit
Command 2nd
-q -dUseCropBox -dBATCH -dDOINTERPOLATE -dMaxBitmap=300000000 -dAlignToPixels=0 -dNOPAUSE -dSAFER -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -dPDFFitPage -dPrinted=false -r144 -g200x199 -sDEVICE=jpeg -dJPEGQ=100 -sOutputFile="output.jpg" "input.pdf" -c quit
As you can see, command has difference in -g parameter only.
In first command I have used -g200x200 and in second command -g200x199.
First command gives rotated JPEG while second command gives UN-rotated JPEG file.Is there any utility inside ghostscript which differentiate my command from height and width perspective.
How should I get UN-rotated JPEG image file by using same height and width(-g200x200) while converting PDF to JPEG image file ?
The main answer is 'don't use PDFFitPage'. That feature automatically rotates the output to fit 'best' on the declared media. If that isn't an option then you will have to do some PostScript programming.
You can fnd the code which does the resizing (and rotation) in ghostpdl/gs/Resource/Init/pdf_main.ps, the function /pdf_PDF2PS_matrix

Ghostscript doesn't generate pdf

I've a problem with that command line :
gswin32c.exe -sDevice=pdfwrite -sOutputFile=out.pdf -dNOPROMPT -dNODISPLAY -dNOPAUSE doc.prn-q -c quit
The program runs without any error.If I enable the display option, i can see the Ghostscript image of my document but my PDF is not generated.
Any Ideas ?
Solved
gswin32c -q -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=doc.pdf doc.prn -c quit
Your command line includes 'doc.prn-q' possibly you meant 'doc.prn -q'. Hint, if you are trying to debug a problem, don't turn off all the messages which might be trying to give you information! (-q is 'quiet' mode).
I finally found the solution, maybe parameters where not well placed in my command line.
gswin32c -q -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=doc.pdf doc.prn -c quit
Thank you for all guys !
Have a nice day
Fabien

How to transform an high def PDF to low def using command line tools?

I've a unix server (mac osx in fact) which transform actually PS files to PDF files. It does this through ps2pdf, with those parameters:
ps2pdf14 \
-dPDFSETTINGS=/prepress \
-dEPSCrop \
-dColorImageResolution=72 \
-dColorConversionStrategy=/LeaveColorUnchanged \
INPUT_FILE \
OUTPUT_FILE
But now I've to adapt this script to have a PDF file as input instead as PS.
So I guess that ps2pdf will not work anymore, and I need something which can reduce the quality of the pdf.
Do you know a tool like this?
The ps2pdf14 script just runs the ps2pdfwr script with -dCompatibilityLevel=1.4, which in turn uses gs with various parameters. You can examine that script to see the options.
You could run gs directly, putting in the various options added by the scripts and your own -d options (which are passed directly to gs). I.e. try:
gs \
-sDEVICE=pdfwrite \
-dPDFSETTINGS=/prepress \
-dEPSCrop \
-dColorImageResolution=72 \
-dColorConversionStrategy=/LeaveColorUnchanged \
-q \
-dNOPAUSE \
-dBATCH \
-sOutputFile=OUTPUT_FILE \
INPUT_FILE
Your command should works with PDFs: Ghostscript (backend for ps2pdf) accept PDF as input file. I just tested ps2pdf from Ghostscript 9.04 and it works

Using Ghostscript to convert JPEG to PDF

What are the parameters that I should pass? The Ghostscript version I'm using is 8.71.
https://gitlab.mister-muffin.de/josch/img2pdf
As mentioned by PleaseStand, GhostScript (edit: prior to v9.23) will decode the JPEG data, resulting in generation loss, as well as performance "ten to hundred" times worse than img2pdf.
Edit: Ghostscript 9.23 (2018-03-21) added a "JPEG Passthrough" capability that resolves the generation-loss/performance issue.
ImageMagick (i.e. convert) also decodes and re-encodes the images.
gs \
-dNOSAFER \
-sDEVICE=pdfwrite \
-o foo.pdf \
/usr/local/share/ghostscript/8.71/lib/viewjpeg.ps \
-c \(my.jpg\) viewJPEG
reads my.jpg and produces foo.pdf. You will have to find where your installation installed the PostScript program viewjpeg.ps.
I've been using the same basic command line Henry gave in his answer for quite some time now in a simple Bash script, with a few tweaks.
My full script converts multiple JPEG images to a multipage PDF, using this modified command:
gs \
-sDEVICE=pdfwrite \
-o foo.pdf \
/usr/local/share/ghostscript/9.02/lib/viewjpeg.ps \
-c "(1st.jpg) viewJPEG showpage \
(2nd.jpg) viewJPEG showpage \
(3rd.jpg) viewJPEG showpage \
(last.jpg) viewJPEG showpage"
It is called like this:
jpegs2pdf.sh output.pdf file1.jpeg [file2.jpeg [file2.jpeg [...]]]
The problem is that this command would use the same (default) page size of Ghostscript (usually Letter or A4 in portrait mode), and each JPEG image will be scaled to fit this pagewidth and/or pageheight, being placed on the lower left corner.
My script makes each PDF page use the same page dimensions as the original JPEG for the page. For auto-discovery of the JPEG's dimensions, I use ImageMagick's identify command:
identify -format "%[fx:(w)] %[fx:(h)]" some.jpeg
Here is the code of the full script:
#!/bin/bash
#
#############################################################################
#
# Shellscript to convert a set of JPEG files to a multipage PDF.
#
# Requirements: (1) Ghostscript needs to be installed on the local system.
# (2) ImageMagick needs to be installed on the local system.
#
# Usage: jpegs2pdf.sh output.pdf file1.jpeg [file2.jpeg [file2.jpeg [...]]]
#
# Copyright (c) 2007, <pipitas#gmail.com>
# Use, distribute and modify without any restrictions.
#
# Versions:
# v1.0.0, Jul 12 2007: initial version
# v1.0.1, Jan 07 2011: set viewJPEG.ps path (self-compiled GS 9.02)
#
#############################################################################
outfile=$1
shift
param=""
for i in "$#" ; do
dimension=$(identify -format "%[fx:(w)] %[fx:(h)]" "${i}")
param="${param} <</PageSize [${dimension}]>> setpagedevice (${i}) viewJPEG showpage"
done
gs \
-dNOSAFER \
-sDEVICE=pdfwrite \
-dPDFSETTINGS=/prepress \
-o "$outfile" \
/usr/local/share/ghostscript/9.02/lib/viewjpeg.ps \
-c "${param}"
alternatively on some linux distros convert pic1.jpg pic2.jpg out.pdf does the job with mixed results
I have Ghostscript version 9.10, so the command with the below line DIDN'T WORKED FOR ME
/usr/local/share/ghostscript/9.02/lib/viewjpeg.ps
so I modifid the command and edited the line and insted used this, IT WORKED FOR ME
viewjpeg.ps
So the NEW MODIFIED COMMAND IS below:
gs \
-sDEVICE=pdfwrite \
-o foo.pdf \
viewjpeg.ps \
-c "(1st.jpg) viewJPEG showpage \
(2nd.jpg) viewJPEG showpage \
(3rd.jpg) viewJPEG showpage \
(last.jpg) viewJPEG showpage"
GhostScript is a PostScript interpreter, so it does not directly support a JPEG input, only a JPEG output. That said, it does support JPEG decompression (except for progressive JPEG).
There's a PostScript program and accompanying shell script that you can use to take advantage of this called jpeg2eps. To get a PDF, most systems have the script pstopdf available for use, which runs each of the input files (you would use the output of the jpeg2eps script) through GhostScript.

Resources