Is it possible to not render text using the Ghostscript command line? - image

I want to do some image processing in MATLAB. However, my source files are PDF's, so I'm converting them to images using the Ghostscript command line.
gs -dNOPAUSE -dBATCH -sDEVICE=pngalpha -r300 -sOutputFile=test%d.png test.pdf
However, there is some text overlaying the images I would like to process. Is it possible to disable the rendering of fonts? Ugly workarounds are acceptable too, like forcing gs to use an empty font (does such a thing exist?) or something.

If you are using a recent version of Ghostscript (and if you aren't, then upgrade) you can use:
-dFILTERTEXT
See Ghostscript documentation: Use.htm => "Other parameters".

Related

Convert RGB pdf to CMYK preserve pdf

I am using ghostscript 9.25 windows.
I am trying to convert RGB pdf to CMYK preserve pdf using following command:
gswin32c.exe
-dSAFER -dBATCH -dNOPAUSE -dNOCACHE -sDEVICE=pdfwrite -sColorConversionStrategy=CMYK -dProcessColorModel=/DeviceCMYK -dAutoFilterColorImages=false -dAutoFilterGrayImages=false -sOutputFile=out.pdf input.pdf
input.pdf file here
https://www.dropbox.com/s/8jfnov526nhb9m9/blank.pdf?dl=0
output.pdf file here
https://www.dropbox.com/s/ftrmm32mmixaxqh/out.pdf?dl=0
but my output becomes light compared adobe output, expected result is it should be dark when i do in adobe CMYK preserve option, i am getting little dark compared to ghostscript output. Am I doing anything wrong?
Should I use any icc profile?
Thanks
You say you are using ImageMagick, yet you give a Ghostscript command line....
I presume that when you say CMYL you mean CMYK.
There is nothing immediately obviously wrong with your command line, but you have given no example file, nor any reason why you expect the result to be 'dark'.
If you want to control the conversion then you will need to supply at least one and possibly up to 4 ICC profiles. You will certainly need a CIE->CMYK Output profile, and you might like to supply ICC profiles for Gray->CIE, RGB->CIE and CMYK->CIE as well, in order to override the default ones Ghostscript is using.
[EDIT]
The problem is nothing to do with colour conversion. Your original file contains nothing except a very large image, which is compressed with the Flate filter (lossless). It looks like this:
You've turned off auto filtering, but you haven't told Ghostscript which compression filter to use for images, so it sticks with the default, which is JPEG (DCT). The image now looks like this:
For the nature of your original image, JPEG (lossy) compression is an outstandingly bad choice. The output image compresses less well, and it loses fidelity. You should change to using Flate compression instead of JPEG for images of this kind.
By the way, the image in your original PDF file was defined in CMYK space already.

Ghostscript doesn't keep landscape page orientation

Example:
Create a one sheet landscape PDF from Excel. Open it using Adobe Reader, where it opens as landscape. Print it using Ghostscript. Open printout using Adobe Reader, and it should still be landscape, but it isn't.
This issues happens whether or not the source is a PDF or Excel itself. I use a PDF source in the example because I figured that it would be easier to illustrate the issue.
I know it can probably be forced to be printed using landscape. What I don't understand is why Ghostscript is not using the orientation of the original document. How can I get Ghostscript to keep the orientation of the original document?
PDFWrite config file:
-I"C:\Program Files\gs\gs9.22\lib";"C:\Program Files\gs\fonts"
-sDEVICE=pdfwrite
-r300
-dNOPAUSE
-dSAFER
-sPAPERSIZE=A4
-dCompatibilityLevel=1.4
-dPDFSETTINGS=/prepress
Redmon config:
#"C:\Program Files\gs\pdfwrite.txt" -sOutputFile="%1" -c 30000000 setvmthreshold .setpdfwrite -f -
Printer driver:
Ghostscript PDF
You've left the AutoRotatePages switch at the default. The default is to rotate pages so that the majority of text is horizontal, if you don't want that, then set -dAutoRotatePages=/None.
Since you apparently already have a PDF file ? Why use Ghostscript to create another one ? You stand the chance of losing stuff that way.
Since the input is PDF there is no point in the -sPAPERSIZE switch, since that only sets the dfefault media, which is immediately overridden by the PDF interpreter.
If I were you I wouldn't set -dPDFSETTINGS at all, nor -r300 (the resolution setting is mostly pointless for pdfwrite)

ghostscript how to retain pdf size while converting pdf to grayscale

I am using Ghostscript 8.x to convert a pdf to grayscale.I am using the following command:
gs -dNOPAUSE -dBATCH -q -sOutputFile=- -sDEVICE=psgray 2016-12-15-165043474.pdf | ps2pdf - output.pdf
This successfully converts my pdf to grayscale but I lose the original pdfsize. The resulting pdf has a lot of whitespace looks like A4 size.
My input pdf has fixed width of 3cm (height may vary).I want the output pdf to be of same size.
Please suggest.
Don't use the psgray device! This is seriously deprecated and has been removed totally in recent versions of Ghostscript. By using this you are converting the PDF to PostScript and then converting it back to PDF. More steps than you need (with each conversion potentially introducing problems), and that's where you are getting the default media size from.
Simply use the pdfwrite device to do all the work, but you will need a reasonably recent version of Ghostscript to do it. Possibly more recent than the old version you are obviously using currently.
gs -sDEVICE=pdfwrite -sColorConversionStrategy=DeviceGray -sOutputFile=out.pdf input.pdf

ghostscript option to make a pdf with flattened images

Is there an option to print a pdf in ghostscript as images?
I can use:
gs -dNOPAUSE -dBATCH -sDEVICE=pngalpha -r300 -sOutputFile=p%03d.png my.pdf
Then use imagemagick to make a pdf out of them with:
convert *.png new.pdf
PDF printers seem to have an option that does the same thing that is a checkbox that says "print as image". I could not find anything in the ghostscript docs that sounded like that was an option. There may be a term for it that I just don't know to look for.
It is kind of hard to explain why you would want to take a pdf document that is text and turn it into a document of images of text that is 4 times the size of the original but that is what I want to do.
Currently the only way to do that would be to start with a PDF which contains transparency operations, and select a CompatibilityLevel of 1.3 or less.
I have an idea to implement this feature, but I have not had time to work on it.
You can do it as a 2-pass approach using Ghostscript to render an image, then using the view* scripts to read the image back into Ghostscript and produce a PDF. No better than using convert of course.

can I use Ghostscript to overlay a text (fax) header onto a PDF and/or TIFF?

I'm writing an application that faxes a document (many supported types) provided by the end user. A requirement is that the end user can also provide text to be used as part of a custom fax header.
I've been using Ghostscript to render PDFs as TIFFs and it's been working great so far, but I have yet to find a straightforward way of overlaying the custom header at the top of a PDF. I've tried out a few recommendations:
How can I make a program overlay text on a postscript file?
How can I add a footer to the bottom of each page of a postscript or pdf file in linux?
Add comments to PDF files automagically with regular expressions
Stamp PDF file with control for position of stamp file
... with no luck.
I've used ImageMagick to do this successfully with documents rendered to TIFF via other tools, and I'm aware that ImageMagick can render PDF-to-TIFF on its own. However, I want to stick with Ghostscript because in my experience it has performed better and rendered clearer TIFFs.
Is this possible using Ghostscript and perhaps a PS helper script?
Edit:
Ghostscript (v9.04) is not throwing any errors. For example:
gswin64c -dSAFER -dBATCH -dNOPAUSE -dPDFFitPage -sDEVICE=tiffg3 ^
-sOutputFile=goofy.tif ^
-c "/Courier findfont 12 scalefont setfont 50 765 moveto (header text) show" ^
-f goofy.pdf
... produces a TIFF of the original PDF, but without the text I tried to add. If I append showpage to the postscript one-liner it (predictably, I suppose) prints a new, blank-except-for-header page, which doesn't help me much.
I would use another commandline tool combined with Ghostscript for this task. This tool is pdftk.exe. Then use a 3 step approach:
The task of Ghostscript would be to create an (otherwise empty) page with the header text:
gswin64c.exe ^
-o header.pdf ^
-sDEVICE=pdfwrite ^
-c "/Courier findfont 12 scalefont setfont" ^
-c "50 765 moveto (header text) show showpage"
The task of pdftk would be to overlay (stamp or background) the PDF file with the text header over the original PDF:
pdftk.exe goofy.pdf background header.pdf output goofy-with-header.pdf or
pdftk.exe goofy.pdf stamp header.pdf output goofy-with-header.pdf
The last step is to employ Ghostscript again in order to create your final TIFF output:
gswin64c.exe ^
-dPDFFitPage ^
-o goofy-with-header.tif ^
-sDEVICE=tiffg3 ^
goofy-with-header.pdf
I just tried your exact same approach with your exact same result. Then I removed -dSAFER from my command-line arguments and it works like a charm.
The way I see doping it is appending what you need on the PDF to the PDF file itself - before any conversion - the PDF filew format is designed so that one can append extra information at the end of the file (even information that goes on previous pages).
Unfortunatelly, I never worked on it - so I can'tell you eactly what you need to do - maybe there is aome PDF editing library in a programing language that would make this task easier - else you will have to create the PDF bits yourself. (Tradiditional libraries that render PDF's from some input format won't do, as you have to work inside the structure of your existing document) - but maybe taking a looka t the PDF specification can enlighten you on this approacj, and you check if it is worth:
http://www.adobe.com/devnet/pdf/pdf_reference_archive.html
Another approach there would be to work on the "other end" of your files: layout text on the post-rendered TIFF files using an image manipulation library. This is only possible, of course, if there is a fixed space on the pages reserved for you to add the information.
Sorry for not being able to offer a complete solution

Resources