reHackable / maxio

Companion daemon for the reMarkableā„¢ paper tablet
GNU Lesser General Public License v3.0
156 stars 53 forks source link

PyPDF2 in place of pdftk #21

Open mseri opened 6 years ago

mseri commented 6 years ago

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 commented 6 years ago

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

florian-wagner commented 6 years ago

I like the idea. :+1:

zxdawn commented 6 years ago

Yes! That's better~

Brassfield commented 5 years ago

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 :-)

mkamensky commented 4 years ago

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"
mseri commented 4 years ago

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 commented 4 years ago

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

mkamensky commented 4 years ago

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 commented 4 years ago

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