PDF generated with ghostscript (no output fonts) has defects (missing outlines) - ghostscript

Following of question: Convert PDF to get vectorized text ("convert all text to outlines")
The PDF generated with the gs -o outputPath.pdf -dNoOutputFonts -sDEVICE=pdfwrite inputPath.pdf has a defect. Around some font characters, some outlines have disappeared when I inspect it deeply with Inkscape (View / Display Mode / Outlines). See:
Link of the file for further inspection: https://filetransfer.io/data-package/nwsra9yl#link
How to solve this? Is there an option in the ghostscript command that I could add to solve this? Thanks.

Related

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 PDF to PostScript

I have to convert pdf files (created with jasperreports) to postscript.
I'm using ghostscript (Version 9.19) to make the conversion.
The commmand i'm using is:
gswin64c -dNOPAUSE -dBATCH -sDEVICE=ps2write -sOutputFile=file.ps file.pdf
The conversion is done without problem, but when i open the postscript file generated (using GSview 5.0), the top margin is crop by 2-3 cm, and some information to print is lost.
I have changed the device from ps2write to eps2write, used the property -g<width>x<height> with the page size in pixels, but the problem persist.
The file is to be printed in a preformated paper, so i can not use the postscript generated to print.
Can someone help?
Thanks
Its not possible to say with great certainty, but it sounds like the PDF mediaBox is larger than the media you have specified to GSView.
You can try using the -dDEVICEWIDTHPOINTS and -dDEVICEHEIGHTPOINTS along with -dFIXEDMEDIA and -dPDFFitPage, that should allow you to set up a specific media size, override the size in the PDF file and scale the result to fit the specified size.
Perhaps you could post an example PDF file, without that its very hard to comment sensibly.

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

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".

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