ps2pdf: after update to Ghostscript 9.15 fonts no longer embedded - pdf

I updated Ghostscript from version 9.05 to 9.15. After the update, ps2pdf doesn't use the correct fonts in the conversion from PostScript to PDF anymore.
The fonts in question are not from the 12 default PostScript fonts. fc-list lists them properly and I even made sure that the font-files actually exist.
With gs 9.05 everything worked as expected. The command I use is simply
ps2pdf $FILE $PDF_FILE_NAME
I tried -dEmbedAllFonts=true but to no help.
I use the Generic Mapping Tools to generate my PostScript files. The PostScript file looks correct when opened with Apple Mac OS X' Preview.app:
Only the gs generated PDF lacks the proper fonts:
System:
Ubuntu 12.04.5 LTS (GNU/Linux 2.6.32-042stab092.2 x86_64)
GPL Ghostscript 9.15 (2014-09-22)
GMT 5.2.0_r13493 [64-bit] [4 cores]
I ran out of ideas on what might cause my problem. Your ideas and input are highly appreciated.

Seems to have been raised as a bug at:
http://bugs.ghostscript.com/show_bug.cgi?id=695552
Still waiting to hear a response from the bug reporter there.

You could try to use ps2pdf with the additional option -sFONTPATH:
ps2pdf -sFONTPATH=/path/to/your/fonts $FILE $OUTPUT

Related

Specify default substitution font when converting pdf to image using imagemagick and font is missing

I am using Spatie/pdfToImage that builds on ghost script and imagemagick to on my server:
Take a multiple page pdf from an email using mailgun routing.
Save the pdf in folder /docs_pdf like file.pdf
Use a foreach to loop through each page and save each page as a png to /docs like file_#.png
locally where I use laravel -> valet everything works fine.
On my server using digital ocean through laravel forge the language in a multipaged pdf that is in swedish transforms from normal swedish to a bunch of random letters and signs.
The left is correct (yes, its true. Its Swedish) and the right is wrong:
Someone suggested to me that this is probably a matter of the font missing on the server. The fonts used in the pdf:
<</StemV 68/FontName/PSQHMO+FoundrySans-Normal/FontFile2 216 0 R/FontStretch/Normal/FontWeight 400/Flags 32/Descent -240/FontBBox[-40 -240 960 916]/Ascent 916/FontFamily(FoundrySans-Normal)/CapHeight 667/XHeight 465/Type/FontDescriptor/ItalicAngle 0>>
<</StemV 100/FontName/MLHPWU+FoundrySans-Medium/FontFile2 217 0 R/FontStretch/Normal/FontWeight 400/Flags 32/Descent -241/FontBBox[-42 -241 1008 916]/Ascent 916/FontFamily(FoundrySans-Medium)/CapHeight 667/XHeight 470/Type/FontDescriptor/ItalicAngle 0>>
<</StemV 68/FontName/SUEECI+FoundrySans-Normal/FontFile2 218 0 R/FontStretch/Normal/FontWeight 400/Flags 4/Descent -240/FontBBox[-40 -240 960 916]/Ascent 916/FontFamily(FoundrySans-Normal)/CapHeight 667/XHeight 465/Type/FontDescriptor/ItalicAngle 0>>
<</StemV 48/FontName/KIDDUY+FoundrySans-Light/FontFile2 9 0 R/FontStretch/Normal/FontWeight 400/Flags 32/Descent -248/FontBBox[-28 -248 978 924]/Ascent 924/FontFamily(FoundrySans-Light)/CapHeight 667/XHeight 458/Type/FontDescriptor/ItalicAngle 0>>
Here is configuration of fonts in imagemagick and ghostscript:
https://www.imagemagick.org/script/resources.php
how can this be solved?
Update:
I have now made a clean install on a new server.
Installed Imagick and spatie/pdfToImage
As suggested by KenS I ran
gs -sDEVICE=png16m -o out%d.png
terminal output
forge#Server:~/app/storage/app/public/files$ gs -sDEVICE=png16m -o test_out%d.png file.pdf
GPL Ghostscript 9.22 (2017-10-04)
Copyright (C) 2017 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 2.
Page 1
Page 2
the document rendered the same = wrong.
I am at a complete loss.. Don't know what next step might be..
Update2:
I also run the convert imagemagick commando and the img rendered the same way also.
So even if I do it with ghostscript solo, imagemagick or spatie/pdfToImage it gives me the same output
Well, the current version of Ghostscript (9.25) renders this acceptably for me; that is the text appears to be correct. All the fonts are embedded, so there shouldn't be any problems.
And this means that even if you did replace the default font substitution, it wouldn't help, because Ghostscript shouldn't be using the default font, it will be using the fonts embedded in the PDF file.
Without knowing what version of Ghostscript you are using (I see from a later comment that its 9.25), or the command line that is used to start it, I can't really do a like-for-like comparison. Its hard for me to see how you could be getting such a different result though. That looks like Ghostscript has failed to find the embedded fonts.
Its possible that whatever package you are using has done something 'unfortunate'. The various package maintainers on Linux add their own patches, and sometimes modify the way that Ghostscript is built. Possibly that has broken something.
If you are able to build Ghostscript yourself you could try cloning our Git repository and doing that. You could also try downloading the Linux binaries off our website. They won't work with every Linux distribution (different ABI) but you can try, you might be lucky.
You could also try running Ghostscript directly on the PDF file. Something like:
gs -sDEVICE=png16m -o out%d.png
should produce 2 PNG files, out1.png and out2.png. It will also produce a bunch of stuff on the terminal. That back channel output is valuable information for me so if you can reproduce the problem, I'd like to see that too.
One last thought; its possible to have more than one version of Ghostscript installed simultaneously, its possible that your current setup is using an old version of Ghostscript.
I can't help you with ImageMagick or Spatie, but if you can debug those to the point where you can reproduce the problem with a plain Ghostscript command line then I can look further at it.
Finally got it to work. I want to first give kudos to KenS that really helped me, and without him it would not have worked.
This is what I did:
1 - I removed Ghostscript:
sudo apt-get purge --auto-remove ghostscript
then
wget https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs925/ghostscript-9.25.tar.gz
tar xvf ghostscript-9.25.tar.gz
Enter the unpacked folder and do
./configure
make
make install
then
sudo ln -s /usr/local/bin/gs /usr/bin/gs
On top of the above I did:
sudo add-apt-repository ppa:glasen/freetype2
and then:
sudo apt update && sudo apt install freetype2-demos

Textext (Inkscape), GhostScript and MaTeX (mathematica) compatibility

The following question has to do with installation of the MaTeX package to Mathematica, and the difficulties I encounter in making it compatible with Inkscape’s Textext (LaTeX addon).
I first summarize my problem in Long story short (I have the detailed series of events in Long story). I then present my questions in Questions and supply some additional information regarding versions of the various programs in Supplementary Information.
Long story short
I am having issues with using both Textext add-on in Inkscape and MaTeX package in Wolfram's Mathematica. I have tried uninstalling and re-installing all related Inkscape programs but nothing seems to change.
Long story
I am using Inkscape to produce figures with LaTeX code (using textext according to this guide https://people.orie.cornell.edu/jmd388/design/guides/textext.pdf). I have previously installed Textext, and Inkscape was working well – allowing me to include LaTeX text in my figures.
I am also using Wolfram Mathematica. To include LaTeX text in Mathematica I needed to install the MaTeX package (from here https://github.com/szhorvat/MaTeX). However, once I did this, Textext stopped working.
I have uninstalled and reinstalled all inkscape’s related programs – pstoedit, ghostscript, GSview, ImageMagick, Textext and Inkscape itself – but still MaTeX wouldn’t work. Textext seems to be working now, but MaTeX does not.
The error Mathematica gives when running the MaTeX package is the following
MaTeX::gserr: Error while running Ghostscript.
After examinning this issue, I have realized that the problem might originate from the Ghostscript version. I have ran the following line in the command:
gswin64c.exe -o mt-gs.pdf -dNoOutputFonts -sDEVICE=pdfwrite mt.pdf
and the outcome I obtain is
**** Could not open temporary file ''
****Unable to open the initial device, quitting.
But when I only put
gswin64c.exe -o mt-gs.pdf -dNoOutputFonts mt.pdf
Ghostscript seems to operate (that is, a pdf window pops-up and immediately closes).
Additionally, when I try to run GS on a different pdf file, I get the following error
Could not open the scratch file encoded_file_ptr_0.
+ c:\users\cjl\artifex\gs-release'9.21\ghostpdl-9.21\base\gdevp14.c:6044: gs_pdf14_devide_push<>: Fatal
GPL Ghostscript 9.21: Unrecoverable error, exit code 255
where the same file works on a different computer's GS (so the file should be OK).
Overall, I cannot use MaTeX at the moment since I get this error, which forces me to produce figures in Mathematica and move them into Inkscape to include axis labels and other notations (such that the fonts are consistent).
Questions
What is wrong with my Ghostscript? How can I fix it?
Has anyone encountered such difficulties before (making Textext and MaTex packages work at the same time)?
Does anyone have an idea of how to fix MaTeX/Textext such that both would work?
Supplementary information
Here are the specs of my OS, as well as the versions of the different involved programs:
Windows 7 64-bit OS.
Mathematica verion 11.1.1.0 for Windows 64-bit.
Inkscape version 0.48
Ghostscript version 9.21
pstoedit and importps version 3.7
ImageMagick version 7.0.7 - Q16
Textext version 0.4.4
MiKTeX 2.9 (updated today).
I would really appreciate any comments and ideas.
Thanks in advance
There is nothing wrong with your Ghostscript command, but the pdfwrite device requires the ability to write temporary files to the system temporary directory. (other devices such as the default display device do not always require the ability to write temporary files)
The empty filename is suspicious in the error, that should not be possible.
There is clearly some kind of problem because the file 'encoded_file_ptr.0' couldn't be created either apparently, and that's a valid filename.
I'd have to guess at some kind of permissions problem. I note that you are running a Windows Ghostscript, are you running this under some kind of Linux-alike ? I'd be suspicious that there is some kind of permissions or access problem on the temp partition if so.
Have you tried running Ghostscript from the WIndows command shell ?

error Converting PDF to PNG - Python 3.6 and GhostScript

I have much trouble to have a code to convert pdf file to png on python 3.6, windows 10.
I know what you are going to say : google it !
But barely everything I've found was on python 2.7. And some packages haven't been updated.
What I've seen so far it's that the best way to do it is using Wand, right ? (I have installed ImageMagick before )
from wand.image import Image
# Converting first page into JPG
with Image(filename='0.pdf') as img:
img.save(filename="/temp.jpg")
# Resizing this image
Here was my second error :
wand.exceptions.DelegateError: PDFDelegateFailed
`The system cannot find the file specified.' # error/pdf.c/ReadPDFImage/809
So i read i need ghostscript. I installed it. But the package is for python 2.7 and it doesn't work. I found python3-ghostscript 0.5.0. https://pypi.python.org/pypi/python3-ghostscript/0.5.0
New error :
RuntimeError: Can not find Ghostscript DLL in registry
So here I needed to install Ghostscript 9 :
https://www.ghostscript.com/download/gsdnld.html
First of all it's not a GPL license ... That's not even a package but a program. I don't know how I can use it in my futures python codes...
and there is still an error :
RuntimeError: Can not find Ghostscript DLL in registry
and i can't find anything for it.
Ghostscript is licensed under the AGPL, the licence can be found in /Program Files (x86)/gs/gs9.21/doc if you want sources then they are available from the Ghostscript Git repository. Note I'm assuming you are running on Windows since you refer to the Registry.
If you install the prebuilt binary then it will create an entry in the Windows Registry, I assume that's what your Python code is looking for but I can't be sure. You should make sure you install the correct word size (32 or 64) version required by Python, if it cares.
You can, of course, simply run Ghostscript to render a PDF file and produce PNG output.
gswin32c -sDEVICE=png16m -sOutputFile=out%d.png input.pdf
This will create one file per page of the input PDF file, use gswin64c for the 64-bit version...
You can alter the resolution of the output with the -r switch, eg -r300
I presume you can simply fork a process from Python. Otherwise you'll have to get someone to tell you what the Python script is looking for in the Registry. Perhaps its looking for a specific version of Ghostscript, or the 32-bit version or something.

How to print PDF on AIX?

I need to print PDF files from AIX 5.3 system. i tried to used Ghostscript software to convert PDF to postscript files but i get the below message.
$ gs
AFPL Ghostscript 8.54 (2006-05-17)
Copyright (C) 2005 artofcode LLC, Benicia, CA. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Xlib: connection to "local:0.0" refused by server
Xlib: Client is not authorized to connect to Server
AFPL Ghostscript 8.54: Cannot open X display `local:0.0'.
**** Unable to open the initial device, quitting.
any help would be appropriated
Thanks
Try using a version of Ghostscript less than 8 years old.....
Basically your command line uses the display device (because you haven't asked for anything else, and that's the default) which on a *nix system is the X client. Clearly you aren't running an X server, so it doesn't work.
You really, really need to be using something more recent, even if you get that ancient version working, the output will be not very good.
gs without arguments tries to open a window, but you are not working in a graphical environment, or it is not set up properly.
I do not know if your ghostscript version is capable enough to convert pdf, but why not give it a try. Graphical environment is not required:
gs -dNOPAUSE -dBATCH -dSAFER -sDEVICE=ps2write -sOutputFile=myfile.ps -f myfile.pdf
More comfortably, see if you have pdf2ps available or if it can be installed. It is a shell script using gs. Just call it like pdf2ps myfile.pdf myfile.ps.

Convert: Postscript delegate failed

I am trying to convert a PDF to JPEG:
$ convert pdf-test.pdf pdf-test.pdf.jpg
However, I am getting this error:
convert: Postscript delegate failed `pdf-test.pdf': No such file or directory # error/pdf.c/ReadPDFImage/664.
convert: missing an image filename `pdf-test.pdf.jpg' # error/convert.c/ConvertImageCommand/3015.
Currently I am using this version of GS and ImageMagick on Mac OS X Lion:
$ gs -v
GPL Ghostscript 9.02 (2011-03-30)
Copyright (C) 2010 Artifex Software, Inc. All rights reserved.
$ convert -version
Version: ImageMagick 6.7.1-1 2011-07-21 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
Features: OpenMP
Can anybody enlighten me on this?
I was receiving the same error message. I then installed gs and the same command worked properly after that.
Try install GS:
$ brew install gs
Well, its telling you thre is no such file or directory. Presumably you have checked the file exists. Have you tried using ./pdf-test.pdf, or using a fully-qualified path ?
Have you tried opening the file directly with GS rather than using ImageMagick ? Just to check the fact that GS is working properly. Somthinhg like:
gs ./test-pdf.pdf
ought to open the PDF file in a window.
ImageMagick sometimes throws this error when you choose too big resolution. Use -density parameter to limit it, e.g. -density 200.
I've encountered this problem today, and it seemed to relate to the overflowing of the /tmp volume. Specifically, it's the magick-* files that were overflowing the storage.
Freeing up the /tmp files solved the problem for me.
I encountered the same problem with MAMP 3.05 on Mac OS X 10.6.8 when trying to convert PDF files with PHP and Imagick to other formats. Conversion doesn't work and gives an error like "Postscript delegate failed... No such file...".
There is already a "gs" file in /Applications/MAMP/Library/bin/lib which comes when installing MAMP 3.05 package. But unfortunately, this file seems not to be in its good location, and this may explain why Ghostscript doesn't work.
The right place for "gs" file is /usr/bin. I tried to put an alias of the "gs" file from MAMP folder to /usr/bin, but it didn't work.
The good method is to make a new install of GS. Download the installer package from http://pages.uoregon.edu/koch/. The last update is 9.14, but on their site, they tell it is buggy in some cases. For this reason, I prefered to install Ghostscript 9.10.
When downloaded, launch the Ghostscript package. It's very easy ! GS installs itself in /usr/local/bin. Copy the "gs" alias from /usr/local/bin to /usr/bin. To do this, obviously, you must reveal hidden files in the finder with a tool like Onyx, choose your MAC OS X version at http://www.titanium.free.fr/downloadonyx.php
Restart MAMP and/or your computer. Now GS works properly, and PDF files can be converted to other picture formats.
Hope be helpful.
I got an extremely similar error message from PHP/Imagick/GS, it turned out the pdf in question was password-protected / encrypted. So maybe that's another possible cause.