0

As in this question,

Assume that you have some text in parts of your LaTeX document that you only want people with a password to see. A reason could e.g. be a case with an guiding answer. You want to make the case public but the answer only to teachers.

I would like to have a link action in the PDF that, when clicked, will decrypt the content after asking for a password, using the Adobe Acrobat Javascript API. (Motivated by this question and answer: How to add print link action of specific pages?)

You can choose any source of encrypted material as a test ASCII content, but a minimum example is in the code below. In the answers to the question Encrypt and decrypt parts of text in a LaTeX source file, it is indicated that the problem of encrypting parts of an ASCII file is really an easy piece of the main task, which can be done by a good editor such as Emacs.

In the code below, which is based on this answer, the line \password"this.getField("myinput").value; tries to cast the user input to integer. This does not work. How can I make it work?

\documentclass{article}
\usepackage{fontspec}

% https://tex.stackexchange.com/a/275434/13173
\newcount\password
\newcount\crycount
\newcount\crycounta
\newcount\crycountb

\def\private#1{%
    \ifx#1\end
        \expandafter\end
    \else
        \crycount`#1
        % ↓↓↓ some math involving \crycount and \password
        \advance\crycount-\password
        \crycounta\crycount\crycountb\crycount\divide\crycounta16\multiply\crycounta16\advance\crycountb-\crycounta\divide\crycounta16
    \xdef\crychara{\ifcase\crycounta0\or1\or2\or3\or4\or5\or6\or7\or8\or9\or a\or b\or c\or d\or e\else f\fi}
    \xdef\crycharb{\ifcase\crycountb0\or1\or2\or3\or4\or5\or6\or7\or8\or9\or a\or b\or c\or d\or e\else f\fi}
        % ↑↑↑ some math involving \crycount and \password
        \xdef\crystring{\crystring\string^\string^\crychara\crycharb}
        \expandafter\private
    \fi
}

% https://tex.stackexchange.com/a/387474/13173
\usepackage{xparse,calc}
\usepackage{eforms

\begin{document}

 \medskip
 \textField[
    \Ff\FfMultiline
    \Ff\FfDoNotSpellCheck
           ]
  {myinput}{\dimexpr\linewidth-10ex}{5\baselineskip}


If key is set to be 2600, you can see the hint below:
\password"2600
\def\crystring{}
\begin{private}
    ♕♳♥☠♭♡♴♨♥♭♡♴♩♣♡♬☠♩♮♤♵♣♴♩♯♮☠♯♮☠☤♜♬♡♭♢♤♡☤☮
\end{private}

\newwrite\cryfile
\immediate\openout\cryfile=\jobname.cry
\immediate\write\cryfile{\crystring}
\immediate\closeout\cryfile
\input{\jobname.cry}

If key is not 2600, you see random characters:
\password"0
\def\crystring{}
\begin{private}
    ♕♳♥☠♭♡♴♨♥♭♡♴♩♣♡♬☠♩♮♤♵♣♴♩♯♮☠♯♮☠☤♜♬♡♭♢♤♡☤☮
\end{private}

\newwrite\cryfile
\immediate\openout\cryfile=\jobname.cry
\immediate\write\cryfile{\crystring}
\immediate\closeout\cryfile
\input{\jobname.cry}

% TODO how to pass the value as integer there?
\AACalculate{event.value=getField("myinput").value;}
If user input is set to be 7777, you can see the hint below:
\password"this.getField("myinput").value;
\def\crystring{}
\begin{private}
    ♕♳♥☠♭♡♴♨♥♭♡♴♩♣♡♬☠♩♮♤♵♣♴♩♯♮☠♯♮☠☤♜♬♡♭♢♤♡☤☮
\end{private}

\newwrite\cryfile
\immediate\openout\cryfile=\jobname.cry
\immediate\write\cryfile{\crystring}
\immediate\closeout\cryfile
\input{\jobname.cry}

\end{document}

Fig. 1 Output

enter image description here

TeXLive: 2017
OS: Debian 9.1
PDF viewer: Adobe Acrobat 9.x (acroread) installed as described here
Acrotex installation: here

ShreevatsaR
  • 45,428
  • 10
  • 117
  • 149
  • 2
    I might find this question only so pointless because i don't understand what is is about. Reading a pdf is reading a pdf. There shouldn't be any ninja action going on. – Johannes_B Jun 10 '17 at 12:51
  • 8
    You can make a cow fly, but it might be more reasonable to just transport the milk. – Johannes_B Jun 10 '17 at 12:52
  • 3
    Honestly, linked question https://tex.stackexchange.com/q/275385/1340 does give a sensible problem statement, but this question is indeed very confusing (and you need to click the right link to get to the text). TL;DR. "Assume that you have some text in parts of your LaTeX document that you only want people with a password to see". @LéoLéopoldHertz준영 – Blaisorblade Jun 14 '17 at 01:39
  • 1
    I tried to rewrite the question so that it is easier to understand. – ShreevatsaR Oct 07 '17 at 14:45
  • 1
    Your approach does not make sense and will not work. Note that TeX completely processes its input and generates a PDF file; it cannot know what password will be entered by the user in future (there is no possible way of sending the user-entered value backwards in time to the TeX processor which ran earlier). So the decryption has to happen inside the PDF reader (in javascript code, say). (That is possible, but in that case it will probably be easier to populate the decrypted text into some form: that text won't be typeset with TeX.) – ShreevatsaR Oct 09 '17 at 20:18
  • @ShreevatsaR Can you please give an example about the Javascript thing you mention? – Léo Léopold Hertz 준영 Oct 13 '17 at 13:23

0 Answers0