maxio icon indicating copy to clipboard operation
maxio copied to clipboard

PyPDF2 in place of pdftk

Open mseri opened this issue 7 years ago • 9 comments

We could reduce the dependencies of the package by moving to PyPDF2 (https://github.com/mstamy2/PyPDF2). In this way we could have a fully pythonic implementation of the tools that is easier to make corss-platform.

If you think this could be interesting, I am going to investigate it as soon as I have some time

mseri avatar Jun 07 '18 08:06 mseri

Also pdfrw (https://github.com/pmaupin/pdfrw) is a pure-python implementation but I have never used it

mseri avatar Jun 07 '18 08:06 mseri

I like the idea. :+1:

florian-wagner avatar Oct 23 '18 21:10 florian-wagner

Yes! That's better~

zxdawn avatar Oct 24 '18 00:10 zxdawn

I suspect you have all moved on, as this project hasn't been touched in a year, but pdftk has been removed from deb & ubuntu due to upstream dependencies (see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=892539)

so changing this dependency would be awesome :-)

Brassfield avatar Jun 07 '19 03:06 Brassfield

Another option is use latex with the pdfpages package. I use the following script, which I call as

pdfstack "${tmpfolder}"/background.pdf "${tmpfolder}"/foreground.pdf "${filename}.pdf"

in place of https://github.com/reHackable/maxio/blob/a0a9d8291bd034a0114919bbf334973bbdd6a218/tools/exportNotebook#L354

(NOT tested much)

#!/bin/zsh

latex='xelatex'

bgf=$1
fgf=$2
out=$3
base=${out:r}

tmpdir=`mktemp -d`
fbase="${tmpdir}/${base}"
fbdir=${fbase:h}

/bin/mkdir -pv $fbdir
/bin/cp $bgf $fgf $fbdir
cat <<EOF > "${fbase}.tex"
\\documentclass{article}
\\usepackage{graphicx}
\\usepackage{pdfpages}

\\begin{document}
\\makeatletter
\\includepdf[pages=-,picturecommand={
  \\includegraphics[page=\\AM@page]{${bgf:t}}
}]{${fgf:t}}
\\makeatother
\end{document}
EOF

cd $fbdir
${latex} $fbase
cd -
cp "${fbase}.pdf" "${base}.pdf"

mkamensky avatar Nov 18 '20 10:11 mkamensky

My suggestion here was to reduce the need for external dependencies, but your script is quite neat and also more portable than the original

mseri avatar Nov 18 '20 12:11 mseri

We should probably collect all these solutions somewhere since in this repo looks like there is not much of a chance to make changes

mseri avatar Nov 18 '20 12:11 mseri

My suggestion here was to reduce the need for external dependencies, but your script is quite neat and also more portable than the original

Sure. For me latex and pdfpages are basic tools, so this indeed saved me a lot of dependencies (all the java stuff around pdftk), but of course it depends on the setup

mkamensky avatar Nov 19 '20 17:11 mkamensky

My suggestion here was to reduce the need for external dependencies, but your script is quite neat and also more portable than the original

By the way, it seems that the list of dependencies in the README is completely off...

mkamensky avatar Nov 19 '20 17:11 mkamensky