3

I would like to create invisible bookmarks/anchor points in my PDF. I want something like \pdfbookmark but with an invisible parameter. Does this exist?

After experiments and reading, I determined that PDFs have anchors of two types:

(comments from the perspective of an outline in a PDF viewer)

  • bookmarks (visible \pdfbookmark{bookmark}{hyperrefuid})
  • named destinations (invisible \hypertarget{nameddestination}{bodytext})

It seems that XeLaTeX is not able to create named destinations, unless I am doing something wrong. Named destinations by hyperref broken for XeTeX 3.14159265-2.6-0.99992 (TeX Live 2015/dev/Debian)

What do I mean? I mean literally a bookmark's text does not show up in the list of bookmarks when opened in a PDF viewer, but does show up when opened in something like PDFedit.

Specified in the Adobe PDF Standards Documentation http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf

I tried searching for "hidden" or "invisible" in the hyperref and extension of that bookmark package, but I did not find any results.

Situation

I have a PDF with many languages as parts.

  • Danish da
  • German de
  • Greek el
  • English en
  • Spanish es
  • Italian it
  • Dutch nl
  • Norwegian (general) no
  • Portugese pt
  • Turkish tr

If a program is configured to run in language German, then the application will automatically jump to the beginning of the German language.

Implementation

I'd like to add a hidden bookmark at the beginning of each \ithinputlanguagefile. I could use #1 for the bookmark text.

% #1 = de
% #2 = German
% #3 = file
\newcommand{\ithinputlanguagefile}[3]{%
  \bookmarksetupnext{bold,open=false} % setup bookmark
  \newpage\pdfbookmark{#2}{bkm#1}%\pdfbookmark[level]{text}{internalNameId} from hyperref
  \phantomsection % Necessary to correct link in Language Directory
  \etoctoccontentsline{part}{#2}% 
  \setcounter{section}{0}% reset section so first sec in new lang starts at 1
  \renewcommand*{\theHsection}{chX.\the\value{runningsectioncounter}} % Keeps hyperref happy (provides unique section numbers instead of using the section counter)
  \input{#3}%input the language file
}

This results in a list of language names in my bookmarks. I also would like invisible bookmarks whose "text" is something like #1 in this example, but is not visible in bookmarks when opened with a pdf viewer.

Example

I would hope that this question does not need a minimal example. I could provide one upon request.

2 Answers 2

2

I apologise in advance for the half baked answer. I'm not 100% percent on this as I do not know much about the PDF specification. However, Adobe Reader has the ability to jump to 'named destinations' within a file and may be suited to what you are looking for.

In your document add \usepackage{hyperref} to your preamble and \hypertarget{destname}{} where needed.

Traditionally, you could then open the document with: acroread /a "nameddest=destname" doc.pdf with the desktop version of Adobe Reader. This has since changed with Windows 10 with the new app form but I would assume the way to access it is still out there.

If through the web, links to http://example.org/doc.pdf#nameddest=destname should also work as defined by RFC3778 sec. 3.

5
  • 1
    The named destination is not being created as you explained. Could you demonstrate this? I just noticed that it works with LaTeX, but seems to break with XeLaTeX :( May 25, 2016 at 12:58
  • 1
  • @macmadness86 Have you tried the configuration file change as suggested in the linked question? May 26, 2016 at 6:14
  • Unsuccessfully, yes. I will experiment more soon. May 26, 2016 at 6:18
  • @macmadness86 Interesting observation I just made, please test to see if it works. Can you access the sections using nameddest=section.3 as defined by the TOC? May 26, 2016 at 6:52
1

Possible Workarounds

Note: These are not solutions to the question asked directly, however offer alternative methods to achieve the same result.

These methods may or may not suit your needs, but at least offer some 'food for thought'.

Method 1: XML Page Index

If a program is configured to run in language German, then the application will automatically jump to the beginning of the German language.

As mentioned, this file is being opened by a program. Hence a programmatic way of accessing the file is possible.

This can be achieved by using the following code as follows.

\documentclass[10pt,a4paper,final]{article}
\usepackage{hyperref}


\newcommand{\openlangxmlfile}{%
    \newwrite\langindexxml%
    \immediate\openout\langindexxml=langindex.xml %
    \immediate\write\langindexxml{<?xml version="1.0"?>}%
    \immediate\write\langindexxml{<toc>}}

\newcommand{\writelangxmlfile}[2]{%
    \immediate\write\langindexxml{%
        <language name="#1" abbr="#2">\thepage</language>%
        }}

\newcommand{\closelangxmlfile}{%
    \immediate\write\langindexxml{</toc>}%
    \immediate\closeout\langindexxml}


\begin{document}
    \openlangxmlfile

    \section{da: Danish}
    \newpage
    \writelangxmlfile{Danish}{da}

    \section{de: German}
    \newpage
    \writelangxmlfile{German}{de}

    \section{el: Greek}
    \newpage
    \writelangxmlfile{Greek}{el}

    \section{en: English}
    \newpage
    \writelangxmlfile{English}{en}

    \section{es: Spanish}
    \newpage
    \writelangxmlfile{Spanish}{es}

    \closelangxmlfile
\end{document}

This will generate an XML file (like below) that can be parsed for page numbers and then used with "page=X" of the PDF open parameters.

<?xml version="1.0"?>
<toc>
<language name="Danish" abbr="da">2</language>
<language name="German" abbr="de">3</language>
<language name="Greek" abbr="el">4</language>
<language name="English" abbr="en">5</language>
<language name="Spanish" abbr="es">6</language>
</toc>

Method 2: Seperate Documents

This is the most simple and effective option of the workarounds. Each README or document is saved as a separate file within a language pack/folder. The program then can find all the appropriate files in the same location.

i.e. In your program all English files are in .\lang\en\ and all German files are in .\lang\de.

To automate this you could call your compiler using the below command where en.body.tex, ge.body.tex, etc. are the contents of the files.

for %i in (*.body.tex) do pdflatex -jobname=%i main.tex

Your main.tex file would look like:

\documentclass[...]{article}
% common preamble

\begin{document}
    % common title info

    \input \jobname.body.tex

    % common end notes
\end{document}

See Martin's answer for more info on this.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .