Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyPDF2 in place of pdftk #21

Open
mseri opened this issue Jun 7, 2018 · 9 comments
Open

PyPDF2 in place of pdftk #21

mseri opened this issue Jun 7, 2018 · 9 comments

Comments

@mseri
Copy link

mseri commented Jun 7, 2018

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
Copy link
Author

mseri commented Jun 7, 2018

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

@florian-wagner
Copy link
Contributor

I like the idea. 👍

@zxdawn
Copy link

zxdawn commented Oct 24, 2018

Yes! That's better~

@Brassfield
Copy link

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
Copy link

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

pdftk "${tmpfolder}"/background.pdf multistamp "${tmpfolder}"/foreground.pdf output "${filename}.pdf"

(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
Copy link
Author

mseri commented Nov 18, 2020

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
Copy link
Author

mseri commented Nov 18, 2020

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
Copy link

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants