0

So recently I managed to create a set of PHP scripts that allows users of a dumbphone to upload a PDF file and view it as JPG images. It works perfectly. I tested it and it seems to work fine in most cases. Also the load is perfectly balanced so no problems so far and I am ready for a serious amount of traffic!

My problem occurs when a user uploads a PDF file that does not have fonts embedded and which uses fonts that are not recognized by Ghostscript. Would it be possible to set a default fallback font to prevent Ghostscript from trowing errors?

Setup: OS: Debian

How does it work: I use the "convert" command provided by imagick to convert pdf's to jpeg's. No additional parameters are set. I am not sure how my Ghostscript/Imagick settings are, but I don't think there's anything special to it. If you need to know something about the install, please provide me with the location of the specific config file and the setting: I will do my best to provide it as soon as possible.

If there's anything else you need, feel free to ask! Thanks in advance!

2 Answers2

0

yes its possible you can add this parameter that points to the font folder in windows for instance, during the ghostscript process, it will start to get the fonts from this path

  -sFONTPATH=c:/windows/fonts 

also note that you can download and add another fonts that are not available in windows fonts folder.

As for the setup issue, for me im using ghostscript to convert PDFs into images, why do you want to use imagemagick? as for this part no parameters are required, in my case i was playing with parameters to increase the quality of the generated images, as an advice you can add this param to you ghostscript to control the quality of your generated images

  -r150 

as per ghosscript documnation here

you can supply Ghostscript with the command line option: -dPDFNOCIDFALLBACK. By combining -dPDFNOCIDFALLBACK with -dPDFSTOPONERROR a production workflow can force a PDF with missing CIDFonts to error, and avoid realising a CIDFont was missing only after printing.

mmoghrabi
  • 1,233
  • 1
  • 14
  • 23
  • I am on Linux and it won't be ever possible to install all fonts a user might use, so replacing the font with a different font seems OK. You are right, I could use Ghostscript instead of Imagick, but that won't fix the font-problem. – TheUnpragmaticProgrammer Sep 26 '13 at 07:28
  • i've edited my answer, you can read more in the documentation, however in linux you can add a folder with fonts and refer to it in the script as well, hope this helps – mmoghrabi Sep 26 '13 at 07:53
  • Guess the real problem is that the PDF the user uploads is not a correct PDF? "Consequently, if you want to handle any PDF document with non-embedded CID fonts (which isn't a correct PDF), you need to create a suitable lib/cidfmap by hand, possibly a specific one for each document." - No, the fonts are embedded: ghostscript seems to handle them wrong. – TheUnpragmaticProgrammer Sep 26 '13 at 08:20
  • just notcd from your comment below that your using an old ver of ghostscript, however i even had problems from the new versions after 9.06 , specially 9.07, some PDFs are not working and after posting a ticket to bugs.ghoscript.com some users have recommended 9.06 which is the most stable one for me so far and it works in all the PDFs – mmoghrabi Sep 26 '13 at 08:35
  • I asked the sys admin to have a look at it :) Hope it will fix my problems *fingers crossed* – TheUnpragmaticProgrammer Sep 26 '13 at 10:32
  • I need to do a full server OS upgrade in order to get Ghostscript 9.06 running. Will be doing that this weekend... :) Thanks in advance for both your help! Hope it will work! – TheUnpragmaticProgrammer Sep 26 '13 at 14:53
0

Ghostscript doesn't throw an error on a missing font it attempts a fallback, initially by matching the name against a list of fonts and styles and finally by substituting (usually) Helvetica.

In the case of missing CIDFonts you don't say which kind you see missing) it attempts to substitute and eventually falls back to using DroidSansFallback, which might not have the glyphs but still doesn't raise an error.

So either you are using a version of Ghostscript which is too old to have this feature present (and you don't say what version of GS you are using), or somehow the feature has been broken. The current version is 9.10, I'd suggest you make sure you are using that, and ideally that you have built it yourself since Linux maintainers have a habit of applying distro-specific patches and unusual (in our opinion undesirable) build conditions to Ghostscript.

While you can add additional fonts using -sFONTPATH this won't usually help inthe case of a PDF file with missing fonts because you often won't have the missing fonts on your system either.

user1283633 is quite correct that you don't need to use convert, unless you require additional processing, Ghostscript is quite capable of producing JPEG output directly.

KenS
  • 30,202
  • 3
  • 34
  • 51
  • You are right! This is the error Ghostscript throws: `Substituting CID font resource/Adobe-GB1 for /STZhongsong. Error: /undefinedresource in findresource` – TheUnpragmaticProgrammer Sep 26 '13 at 07:21
  • My version is 8.62, tried upgrade but failed due to no c compiler. I will ask sys admin to take a look at it. – TheUnpragmaticProgrammer Sep 26 '13 at 07:48
  • The current version is 9.10, you should really use that. 8.62 is 5 years old.If you upgrade to 9.06 you will be missing the latest set of features and bug fixes. – KenS Sep 27 '13 at 07:04
  • I am aware of what you are saying and understand it. However @user1283633 stated that he has tested all versions and found that 9.06 is the most stable one at this time. Add to that that the latest package releases for Debain also are 9.06: it's will be easy to install and try if it solves my problem. If it still don't work: will try update 9.10, if that doesn't work also, I'll just hang myself. :) – TheUnpragmaticProgrammer Sep 27 '13 at 07:12