Not Base64, but plain HEX-encoding the PDF output is possible using PdfTeX's \pdffiledump
built-in. Unfortunately, there is no Base64 filedump available in PdfTeX, but perhaps someone could program one in Lua for use with LuaTeX?
The example below writes the hex encoded output to the terminal and into the file \jobname.pdf.hex
. Before piping the terminal output to somewhere, the normal pdftex
output must be stripped, because it cannot be suppressed. The lines
#### \jobname.pdf.hex begin ####
and
#### \jobname.pdf.hex end ####
written on the terminal (STDOUT) may help you the write a filter for stripping.
To restore the PDF, run the xxd
commandline tool on the HEX output:
xxd -r -p myDocument.pdf.hex myDocument.pdf.hex.pdf
Example (runpdflatex
at least twice):
\documentclass{article}
\usepackage{ifthen} %\whiledo
\edef\fileName{\jobname.pdf}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% writes hex encoded \jobname.pdf to the terminal and
% into the file \jobname.pdf.hex
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\IfFileExists{\fileName}{
\typeout{#### \jobname.pdf.hex begin ####}%
\newwrite\OutFile%
\immediate\openout\OutFile=\fileName.hex%
\def\fileoffset{0}%
\edef\filesize{\pdffilesize{\fileName}}%
\whiledo{\fileoffset<\filesize}{%
\edef\ouputLine{\pdffiledump offset \fileoffset\space length 30 {\fileName}}%
\immediate\write\OutFile{\ouputLine}%
\typeout{\ouputLine}%
\edef\fileoffset{\the\numexpr\fileoffset+30\relax}%
}%
\immediate\closeout\OutFile%
\typeout{#### \jobname.pdf.hex end ####}%
}{}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{kantlipsum}
\begin{document}
\kant[1-20]
\end{document}