Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set pdf flags? #74

Closed
alexpacini opened this issue Oct 27, 2018 · 3 comments
Closed

How to set pdf flags? #74

alexpacini opened this issue Oct 27, 2018 · 3 comments

Comments

@alexpacini
Copy link

I quote this question on tex.stackexchange.com


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 gs 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 gs 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.


Is it possible to add an example of usage on the hyperref manual?

@u-fischer
Copy link
Member

You can set the print flag for form field simply by using a boolean option:

\TextField[name=input1,print=true]{blub}

But I see no manual way to add flags to normal links with the exception to use \usepackage[pdfa]{hyperref}: with it /F 4 is added to the links, which means that the print flag is set.

@u-fischer
Copy link
Member

With the new PDF management which is currently in the testphase, you can set the flags like this:

\RequirePackage{pdfmanagement-testphase}
\DeclareDocumentMetadata{uncompress}
  
\documentclass{article}
\usepackage{hyperref}

\ExplSyntaxOn
\bitset_set_true:Nn  \l_pdfannot_F_bitset {Print}
\pdfannot_dict_put:nnn {link/URI}{F} { \bitset_to_arabic:N \l_pdfannot_F_bitset }
\pdfannot_dict_put:nnn {link/GoTo}{F}{ \bitset_to_arabic:N \l_pdfannot_F_bitset }
\ExplSyntaxOff
\begin{document}
\url{https://github.com/latex3/hyperref}

\end{document}  

@aleb
Copy link

aleb commented Sep 1, 2023

The issue could be reopened as it is about adding this useful information to the manual.

In addition, it can be documented what type of PDF objects are produced by \hyperdef, \hyperref, etc so we can figure how we can affect them.

In addition to the URI and GoTo mentioned in the previous comment, there are a few more types of objects:

link/TYPE: [...] TYPE can be one of URI, GoToR, Launch, GoTo or Named.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants