9

To reduce the size of a PDF produced with pdflatex I usually run this command:

$ gs -sDEVICE=pdfwrite        \
     -dCompatibilityLevel=1.4 \
     -dPDFSETTINGS=/printer   \
     -dEmbedAllFonts=true     \
     -dSubsetFonts=true       \
     -dFastWebView=true       \
     -dNOPAUSE                \
     -dQUIET -dBATCH          \
     -sOutputFile=out.pdf     \
      in.pdf

When I updated Ghostscript to version 25 (9.25), the hyperlinks automatically made by hyperref stopped working: they were not any more clickable.

I tried filing a bug on the Ghostscript bugzilla, where they replied that it is the intended behaviour. See this bug report.

Basically, quoting their answer:

If a /Link Annotation has the 'Print' bit of the annotations /Flags value not set, then the PDF interpreter will (by default) not process the annotation. If the PDF interpreter skips the annotation then the pdfwrite device doesn't ever see it.

If the Annotation (of whatever kind) does set the Print bit, then (again in default setup) the PDF interpreter will process the annotation and pass it to the pdfwrite device.

You can change the behaviour of the interpreter. If you set -dPrinted=false, then the interpreter no longer cares about the Print bit of the annotation flag. In this mode it instead checks the NoView bit, if that isn't set, thenit processes the annotation.

In this case, if the NoView bit was set, then the annotation would be skipped.

So you need to know something about the way the annotation has been created, currently.

The reason this is important is that the control (-dPrinted) which was supposed to control whether or not the annotation is processed was being ignored. Obviously that's not the way it was supposed to work, and has been fixed. Its unfortunate that this causes you a problem, and I may well extend the operation of this control in future, but as of now this is behaving as intended.

With the option -dPrinted=false the links are working again (from Ghostscript's manual):

-dPrinted

-dPrinted=false Determines whether the file should be displayed or printed using the "screen" or "printer" options for annotations and images.

With -dPrinted, the output will use the file's "print" options;

with -dPrinted=false, the output will use the file's "screen" options.

If neither of these is specified, the output will use the screen options for any output device that doesn't have an OutputFile parameter, and the printer options for devices that do have this parameter.

$ gs -sDEVICE=pdfwrite         \
     -dCompatibilityLevel=1.4  \
     -dPrinted=false           \
     -dPDFSETTINGS=/printer    \
     -dEmbedAllFonts=true      \
     -dSubsetFonts=true        \
     -dFastWebView=true        \
     -dNOPAUSE -dQUIET -dBATCH \
     -sOutputFile=out.pdf      \
      in.pdf

It makes sense to use this switch, since the hyperlinks are not intended to be printed, of course.

But in case I want to set them, how to set the print flag by default on the hyperlinks created by hyperref?

I tried checking the hyperref manual:

PDF form field macros (\TextField, \CheckBox, ...) support boolean flag options. The option name is the lowercase version of the names in the PDF specification (1.7):

http://www.adobe.com/devnet/pdf/pdf_reference.html

http://www.adobe.com/devnet/acrobat/pdfs/pdf_reference.pdf

Options (convert to lowercase) except flags in square brackets:

  • Table 8.16 Annotation flags (page 608):
    1. Invisible
    2. Hidden (PDF 1.2)
    3. Print (PDF 1.2)
    4. NoZoom (PDF 1.3)
    5. NoRotate (PDF 1.3)
    6. NoView (PDF 1.3)
    7. [ReadOnly (PDF 1.3)] ignored for widget annotations, see table 8.70
    8. Locked (PDF 1.4)
    9. ToggleNoView (PDF 1.5)
    10. LockedContents (PDF 1.7)

but I don't really get how to set them explicitly.

5

I think you can get the Print flag set if you (ab)use the pdfa option.

\usepackage[pdfa]{hyperref}

(see section "5.12 Option pdfa" of the hyperref manual).

This at least seems to work on my local installation (gs 9.25 as required. Without the pdfa option and running your gs command with -dPrinted the hyperlinks are dropped; with the pdfa option the hyperlinks are preserved).

  • Yes, it does. But still wondering how can be done directly. The hyperref manual forgot to do an example... – Alex Pacini Oct 26 '18 at 23:03
  • @AlexPacini: I don't think the PDF form fields include hyperlinks. The PDF form fields, as far as I am aware, refers to forms that you can fill out (such as US tax forms). The commands that the flags in section 5.15 refers to are described in Section 7 of the Hyperref documentation. – Willie Wong Oct 29 '18 at 15:11
  • But from table 8.16 the Annotation flags includes the Print one, or not? – Alex Pacini Oct 29 '18 at 16:04
  • @Alex: the print annotation flag can be applied to individual PDF form fields using hyperref (at least that's how I read the documentation). That doesn't mean it necessarily can be applied to individual hyperlinks. – Willie Wong Oct 29 '18 at 19:00
  • 1
    No, the pdfa option is not a solution: If it is given, then when one wants to print the PDF file, the boxes around the links are printed, making the document less readable. This is certainly not what one wants! – vinc17 Dec 6 '18 at 14:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.