Bug 695175

Summary: can't save PDF file if compiled with hyperref packages
Product: Ghostscript Reporter: evan.cooch
Component: PDF WriterAssignee: Ken Sharp <ken.sharp>
Status: RESOLVED FIXED    
Severity: normal CC: htl10
Priority: P4    
Version: 9.14   
Hardware: PC   
OS: Windows 7   
Customer: Word Size: ---
Attachments: example of failed GS914 compiled files

Description evan.cooch 2014-04-19 10:54:15 UTC
I used GS 9.14 to convert from PS -> PDF in my TeX-based document creation environment (using ps2pdf). If I compile from PS -> PDF, the PDF is generated perfectly -- as far as what I see on the screen, but the moment I try to save it, problems arise *if* the file is compiled using the hyperref package. If I try to save the PDF file (using Adobe Acrobat Pro), I get an error:

'The document could not be saved. There was a problem reading this document (110)'. 

If I turn off hyperref, then compilation and saving work fine -- the problem only arises if saving with hyperref (which I use in many of my longer documents). 

What is important to note is that the problem does not ocur whatsoever if I revert back to GS 9.10. So, something in the change from 9.10 -> 9.14 'broke' something that interacts with hyperref, which generates a PDF file that can't be saved. 

Here are the options I pass to ps2pdf:

-dBATCH -dNOPAUSE -sDEVICE=pdfwrite -r600 -dCompatibilityLevel=1.7 -dPDFSETTINGS=/prepress -dEmbedAllFonts=true

Here is how I'm invoking hyperref:

\usepackage[ps2pdf,bookmarks=true,bookmarksopen=true,bookmarksopenlevel=1,bookmarksnumbered=true,hyperindex=false,linktocpage=false,hidelinks,
             pdfauthor={c.d. darwin},
           pdftitle={Chapter 1 -- basic introduction...},
         pdfsubject={ },
          pdfkeywords={ },
          pdfproducer={ },
          pdfcreator={ }]{hyperref}


I can reproduce the error every time with 9.14, and it doesn't seem to matter if I include bookmarks, or not, or have any bookmarks open, or not (or at what level if open). 

Easy enough to revert back to 9.10, but there is definitely some sort of bug in 9.14. I'm happy to provided supporting files, upon request.
Comment 1 evan.cooch 2014-04-19 10:58:49 UTC
On a hunch, I just tried some other 'PDF readers' -- I can save fine from Sumatra (which is the most minimal), but Adobe Acrobat X Pro fails every time. So, something about the conversion from PS -> PDF using GS 9.14, and when the file contains 'hypperref',  causes Adobe Acrobat to be unable to save the file.
Comment 2 evan.cooch 2014-04-19 11:02:11 UTC
Just tried muPDF -- won't even open the PDF file. 

So, the problem is really, and not entirely due to anything peculiar with Adobe Acrobat.
Comment 3 Hin-Tak Leung 2014-04-19 13:25:48 UTC
Please attach test file(s). 

while I have a TeXlive install, the texlive people (which probably means the majority of TeX people at this time) aren't known to make all the right decision, and do changes ad hoc so we need the versioned generated files from you. 

Just for interests, why are you not using the pdfTeX driver of hyperref? I can only see one reason- encryption, but you can apply encryption with 3rd party tools like pdftk. Going directly via pdfTeX is usually better than ps than ps2pdf.
Comment 4 evan.cooch 2014-04-19 15:03:20 UTC
Created attachment 10842 [details]
example of failed GS914 compiled files

Contains the .ps n .pdf file generated from a chpter compiled using .tex -> .dvi -> .ps -> .pdf

Final step (.ps -> .pdf) using GS 9.14.
Comment 5 Ken Sharp 2014-04-20 09:04:39 UTC
I can't do anything with 'hyperref', I need a PostScript or PDF input file, and a Ghostscript command line to reproduce the problem.

I presume one of the 2 files in the attachment is the one I need, but which one ?...
Comment 6 evan.cooch 2014-04-20 11:36:05 UTC
(In reply to comment #5)
> I can't do anything with 'hyperref', I need a PostScript or PDF input file,
> and a Ghostscript command line to reproduce the problem.

GS command line was already given in the original post (did you read it?)

> 
> I presume one of the 2 files in the attachment is the one I need, but which
> one ?...

What do you mean, which one? The .zip attachment contains an example PS file, and the PDF generated from same, using the commands noted earlier. Said PDF (i) can be opend, but not saved, by Adobe Acorbat Pro, (ii) can be opened and saved using Sumatra, and (iii) not opened at all using muPDF.
Comment 7 Ken Sharp 2014-04-20 11:44:49 UTC
(In reply to comment #6)
> (In reply to comment #5)
> > I can't do anything with 'hyperref', I need a PostScript or PDF input file,
> > and a Ghostscript command line to reproduce the problem.
> 
> GS command line was already given in the original post (did you read it?)

Yes I did, and I saw the command line, which is why I didn;t ask what the command line was.

 
> What do you mean, which one? The .zip attachment contains an example PS
> file, and the PDF generated from same, using the commands noted earlier.
> Said PDF (i) can be opend, but not saved, by Adobe Acorbat Pro, (ii) can be
> opened and saved using Sumatra, and (iii) not opened at all using muPDF.

Right, but I needed to know whether the input file was  the PostScript file, or the PDF file, or what. Its not clear (to me) from your original comment exactly which file was the input file.
Comment 8 evan.cooch 2014-04-20 11:46:58 UTC
(In reply to comment #7)
> (In reply to comment #6)
> > (In reply to comment #5)
> > > I can't do anything with 'hyperref', I need a PostScript or PDF input file,
> > > and a Ghostscript command line to reproduce the problem.
> > 
> > GS command line was already given in the original post (did you read it?)
> 
> Yes I did, and I saw the command line, which is why I didn;t ask what the
> command line was.
> 
>  
> > What do you mean, which one? The .zip attachment contains an example PS
> > file, and the PDF generated from same, using the commands noted earlier.
> > Said PDF (i) can be opend, but not saved, by Adobe Acorbat Pro, (ii) can be
> > opened and saved using Sumatra, and (iii) not opened at all using muPDF.
> 
> Right, but I needed to know whether the input file was  the PostScript file,
> or the PDF file, or what. Its not clear (to me) from your original comment
> exactly which file was the input file.


Sorry, thought it was obvious. My mistake. I generate documents via the sequence  .tex -> .dvi -> .ps -> .pdf. The .zip contains the last 2 pieces of the sequence.
Comment 9 evan.cooch 2014-04-20 11:51:35 UTC
(tried to post this earlier -- can't see it. Apologies if it duplicates...)

Took the 'bad' .ps file (in .zip attachment), and ran it through Adobe Distiller. The generated PDF can be opened, and saved, by any PDF reader I've tried (Acrobat, muPDF, Sumatra, Evince....).

But, if I generate PDF using GS 9.14, problems as described ensue. If I use GS 9.10, everything works perfectly (and has for some time...). As far as I can tell, the hyperref package in LaTeX generates something that when rendered into .PS doesn't play nice with 9.14 (since, if I turn off hyperref, 9.14 works as expected).
Comment 10 Hin-Tak Leung 2014-04-20 14:53:43 UTC
Evan Cooch: The pdf file, gs914_fail.pdf, in the zip file you attached, works fine with mupdf (1.1), Adobe Acrobat Reader (9.5.5), xpdf (3.03), evince (3.10.3, poppler 0.24.3), and presumably every pdf reader which uses poppler (okular, kpdf, etc). All of them opens it without any warnings/messages, except evince, which say:

failed to look up chapter.1
failed to look up section.1.1
failed to look up section.1.2
failed to look up section.1.3
failed to look up subsection.1.3.1
failed to look up subsection.1.3.2
failed to look up subsection.1.3.3
failed to look up section.1.4
failed to look up section.1.5
failed to look up section.1.6
failed to look up section.1.7
failed to look up section.1.8
failed to look up chapter.1
failed to look up section.1.1
failed to look up section.1.2
failed to look up section.1.3
failed to look up subsection.1.3.1
failed to look up subsection.1.3.2
failed to look up subsection.1.3.3
failed to look up section.1.4
failed to look up section.1.5
failed to look up section.1.6
failed to look up section.1.7
failed to look up section.1.8

As I suggested, you really should look into using the pdfTeX driver of hyperref, rather than the ps2pdf one. It is more direct and allows you to embed png and other kind of figures directly, whereas if you go ps2pdf mode, you are limited by postscript, and eps-based figures, which don't allow transparent figures. (png can be semi-transparent).

BTW, I also work in epidemiology and would be interested to read the content of the rest of the document...

Ken: hyperref is a LaTeX package for generating bookmarks/outlines and other cross-references in pdf's. Let's call it the LaTeX's/open-source equivalent of Adobe's pdfmark macros for Words. In the modern usage, it can be used directly to insert those structures into the output pdf without going through an intermediate ps file (This is what I suggest, called the "pdfTeX" driver mode). In the older, more "historical" usage, called the "ps2pdf" driver mode, it inserts pdfmarks into an intermediate postscript files and let Adobe Distiller or ghostscript turn them into bookmark outlines and cross-references. I cannot see anything obviously broken with those, but evince does complain - is there any major changes in that area recently and/or you can spot anything wrong in the pdf in that area?
Comment 11 Hin-Tak Leung 2014-04-20 15:04:42 UTC
A 3-month old dev snapshot binary of mupdf (1.3+, sha1 f54380c ; 1.4 is out?) does complain:

error: invalid page object
error: invalid page object
error: invalid page object
error: invalid page object
error: invalid page object
error: invalid page object
error: invalid page object
error: invalid page object
error: invalid page object
error: invalid page object
error: invalid page object
error: invalid page object
error: invalid page object
error: invalid page object
error: invalid page object
error: invalid page object
error: invalid page object
error: invalid page object

but again, it opens the pdf for viewing okay.
Comment 12 Ken Sharp 2014-04-21 01:21:47 UTC
The main problem that I can see is that the named destinations dictionary is a null object, which causes all the bookmarks to do nothing. Which I would have thought was a more pressing problem than Acrobat being unable to save the file.

The file is unfortunately quite complex, so this is going to take some time.

This looks like its probably the same as (or at least closely related to) 695162 and since that's a much simpler file I'm going to tackle that one first.
Comment 13 evan.cooch 2014-04-21 08:13:41 UTC
(In reply to comment #12)
> The main problem that I can see is that the named destinations dictionary is
> a null object, which causes all the bookmarks to do nothing. Which I would
> have thought was a more pressing problem than Acrobat being unable to save
> the file.
> 
> The file is unfortunately quite complex, so this is going to take some time.
> 
> This looks like its probably the same as (or at least closely related to)
> 695162 and since that's a much simpler file I'm going to tackle that one
> first.


Thanks! I have the option of rolling back to 9.10 for the moment, so no big issues from my end.
Comment 14 Ken Sharp 2014-04-23 01:53:01 UTC
Commit c79b0ee1dbc1cbbcbe406abd4bc47f617ed5cb2c fixes this for me. The problem was the 'unusual' nature of some of the names used as named destinations.

The resulting file did puzzle me slightly as I couldn't persuade the Outlines (bookmarks in Acrobat parlance) to work, but testing with Distiller showed the same result, so I believe this is now working as expected.