Bug 695874 - Error Reading A Content Stream with Font
Summary: Error Reading A Content Stream with Font
Status: RESOLVED INVALID
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: PDF Interpreter (show other bugs)
Version: 9.14
Hardware: PC Linux
: P4 normal
Assignee: Ken Sharp
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-03-18 15:00 UTC by bill.ghostscript
Modified: 2015-03-31 00:47 UTC (History)
1 user (show)

See Also:
Customer:
Word Size: ---


Attachments
.pfd file that cannot be converted by gs (598.29 KB, application/pdf)
2015-03-18 15:00 UTC, bill.ghostscript
Details

Note You need to log in before you can comment on or make changes to this bug.
Description bill.ghostscript 2015-03-18 15:00:10 UTC
Created attachment 11525 [details]
.pfd file that cannot be converted by gs

I cannot read all of pages 3, 6, 7, and 8 of the attached .pdf file with gs.  I can read them with mudraw.  The errors look like 

**** Error reading a content stream. The page may be incomplete.
**** File did not complete the page properly and may be damaged.

**** This file had errors that were repaired or ignored.
**** The file was produced by:
**** >>>> Antenna House PDF Output Library 2.6.0 (Linux) <<<<
**** Please notify the author of the software that produced this
**** file that it does not conform to Adobe's published PDF
**** specification.
Comment 1 Chris Liddell (chrisl) 2015-03-19 00:53:47 UTC
*Our* 9.14 release with a default build, works fine for the entire document.

You left out some rather important parts of the Ghostscript feedback, where it says things like:

Can't find CID font "UnicodeSymbols".
Attempting to substitute CID font /Adobe-Japan1 for /UnicodeSymbols, see doc/Use.htm#CIDFontSubstitution.
   **** Warning: can't process font stream, loading font by the name.

Really, to be sure of correct output, CIDFonts *must* be embedded, there are far too many variables between CIDFonts to reliably substitute. However, Ghostscript does have the ability to "best guess" a subsitute, so....

Either your Ghostscript isn't setup to automatically substitute CIDFonts, or something else has been tweaked in the build to stop it working.


If your system has either DroidSansFallback.ttf or DroidSansFallbackFull.ttf available, or even the MS arial.ttf, try doing:

"./gs -sCIDFSubstPath=<absolute path to font files> -sCIDFSubstFont=<font file> nihms513647.pdf"

That should work. So, for example, on my system, it would be:

"gs -sCIDFSubstPath=/usr/share/fonts/truetype/droid  -sCIDFSubstFont=DroidSansFallbackFull.ttf nihms513647.pdf"

or:

"gs -sCIDFSubstPath=/usr/share/fonts/truetype/msttcorefonts  -sCIDFSubstFont=arial.ttf nihms513647.pdf"
Comment 2 bill.ghostscript 2015-03-19 05:05:41 UTC
Thank you for the quick reply, and apologies for the late-night incomplete bug report.  My system is an up-to-date Ubuntu 14.10 installation without any ghostscript-related customization.

I wasn't using gs directly.  I first found the issue using GraphicsMagick's convert command (and then confirmed with ImageMagick's convert command).  I then went to pdf2ps where I got the same error.

This morning, I tried pdf2ps with the options you suggested, and I still get the same error (the directory and font exist on my computer, too; see output below).  Given your description, is the issue that pdf2ps doesn't use appropriate flags for CIDF substitution?

$ pdf2ps -sCIDFSubstPath=/usr/share/fonts/truetype/droid/ -sCIDFSubstFont=DroidSansFallbackFull.ttf nihms513647.pdf nihms513647.ps
   **** Error reading a content stream. The page may be incomplete.
   **** File did not complete the page properly and may be damaged.
   **** Error reading a content stream. The page may be incomplete.
   **** File did not complete the page properly and may be damaged.
   **** Error reading a content stream. The page may be incomplete.
   **** File did not complete the page properly and may be damaged.
   **** Error reading a content stream. The page may be incomplete.
   **** File did not complete the page properly and may be damaged.
   **** Error reading a content stream. The page may be incomplete.
   **** File did not complete the page properly and may be damaged.
   **** Error reading a content stream. The page may be incomplete.
   **** File did not complete the page properly and may be damaged.

   **** This file had errors that were repaired or ignored.
   **** The file was produced by:
   **** >>>> Antenna House PDF Output Library 2.6.0 (Linux) <<<<
   **** Please notify the author of the software that produced this
   **** file that it does not conform to Adobe's published PDF
   **** specification.
Comment 3 Chris Liddell (chrisl) 2015-03-19 06:32:21 UTC
Good grief... *Finally* worked out what's going on.....

And I am really rather unimpressed with this.

Ubuntu configures Ghostscript to use specific CIDFont substitutes, but does *not* have those fonts as dependencies for the Ghostscript package. As a result, Ghostscript believes it has fonts available, and happily tries to use them, rather than the fallback substitute. Of course, it later turns out those fonts aren't available, and by that time it is too late to recover.

Worse, I cannot actually identify a package which actually includes the fonts 

So, this is a little hacky, but it was all I could do to get it to work (in the time have right now, anyway): here's what you should do.

"sudo mv /var/lib/ghostscript/fonts/cidfmap /var/lib/ghostscript/fonts/cidfmap.notused"

"sudo touch /var/lib/ghostscript/fonts/cidfmap"

Then try again with the -sCIDFSubstPath and sCIDFSubstFont options listed above.
Comment 4 bill.ghostscript 2015-03-19 14:32:47 UTC
Thank you very much for the effort!  After running the following three commands, I still get the same error (below).  Is there a way to force the font or to force using a specific cidfmap

sudo mv /var/lib/ghostscript/fonts/cidfmap /var/lib/ghostscript/fonts/cidfmap.notused
sudo touch /var/lib/ghostscript/fonts/cidfmap
 pdf2ps -sCIDFSubstPath=/usr/share/fonts/truetype/droid/ -sCIDFSubstFont=DroidSansFallbackFull.ttf nihms513647.pdf nihms513647.ps
   **** Error reading a content stream. The page may be incomplete.
   **** File did not complete the page properly and may be damaged.
   **** Error reading a content stream. The page may be incomplete.
   **** File did not complete the page properly and may be damaged.
   **** Error reading a content stream. The page may be incomplete.
   **** File did not complete the page properly and may be damaged.
   **** Error reading a content stream. The page may be incomplete.
   **** File did not complete the page properly and may be damaged.
   **** Error reading a content stream. The page may be incomplete.
   **** File did not complete the page properly and may be damaged.
   **** Error reading a content stream. The page may be incomplete.
   **** File did not complete the page properly and may be damaged.

   **** This file had errors that were repaired or ignored.
   **** The file was produced by:
   **** >>>> Antenna House PDF Output Library 2.6.0 (Linux) <<<<
   **** Please notify the author of the software that produced this
   **** file that it does not conform to Adobe's published PDF
   **** specification.

Upon looking a bit more, there are other files that are part of the cidfmap perhaps:

/etc/ghostscript/cidfmap.d$ ls -la
total 20
drwxr-xr-x 1 root root 280 Apr 27  2012 .
drwxr-xr-x 1 root root  36 Dec  5  2010 ..
-rw-r--r-- 1 root root 475 May 19  2010 90gs-cjk-resource-cns1.conf
-rw-r--r-- 1 root root 504 May 19  2010 90gs-cjk-resource-gb1.conf
-rw-r--r-- 1 root root 546 Nov 21  2011 90gs-cjk-resource-japan1.conf
-rw-r--r-- 1 root root 387 May 19  2010 90gs-cjk-resource-japan2.conf
-rw-r--r-- 1 root root 730 Nov 21  2011 90gs-cjk-resource-korea1.conf
Comment 5 Chris Liddell (chrisl) 2015-03-19 14:42:03 UTC
(In reply to bill.ghostscript from comment #4)
> Thank you very much for the effort!  After running the following three
> commands, I still get the same error (below).

In all honesty, I'm baffled about what/how Ubuntu are doing this, and I don't have time right now to work it. I *will* raise the issue with the Ubuntu maintainer when I get time to discuss it properly.

>  Is there a way to force the
> font or to force using a specific cidfmap
<SNIP>

Yeh, so if you create a directory in your home called something like "gs-res" (do *not* use the string "resource" or any variation thereof). If you want to avoid clutter, you might choose ".gs-res". In that directory create an empty cidfmap file ("touch gs-res/cidfmap"). Then try running Ghostscript with "-I<full path to for directory>" plus the two options give above. So again on my system it would be:

"gs -I/home/cliddell/gs-res -sCIDFSubstPath=/usr/share/fonts/truetype/droid  -sCIDFSubstFont=DroidSansFallbackFull.ttf nihms513647.pdf"

If that works, then I can tell you how set your environment so you won't have to give the -I option for every Ghostscript invocation.
Comment 6 bill.ghostscript 2015-03-30 19:52:36 UTC
Apologies, I just realized that I didn't respond to your last message.  The suggested steps did not fix the error for me.  I just submitted a bug to Ubuntu (https://bugs.launchpad.net/ubuntu/+source/ghostscript/+bug/1438494) pointing them here.
Comment 7 Chris Liddell (chrisl) 2015-03-31 00:47:20 UTC
(In reply to bill.ghostscript from comment #6)
> Apologies, I just realized that I didn't respond to your last message.  The
> suggested steps did not fix the error for me.  I just submitted a bug to
> Ubuntu (https://bugs.launchpad.net/ubuntu/+source/ghostscript/+bug/1438494)
> pointing them here.

Okay, thanks, I was going to submit a Ubuntu bug once (if) we'd worked out a resolution for your issue.

If I can remember my launchpad details, I will comment on the bug......

I'm going to close this because this is really a packaging issue, rather than a core Ghostscript issue.

FWIW, there's a minimal gs binary available here:
http://www.ghostscript.com/download/gsdnld.html

which might do for you in the meantime.