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

pdftk no longer maintained, consider using something else? #5

Closed
rocketraman opened this issue Aug 11, 2023 · 20 comments
Closed

pdftk no longer maintained, consider using something else? #5

rocketraman opened this issue Aug 11, 2023 · 20 comments

Comments

@rocketraman
Copy link

rocketraman commented Aug 11, 2023

Hello, this looks like a really useful tool. However, it depends on pdftk, which is no longer maintained. For example, Fedora retired this package six years ago: https://src.fedoraproject.org/rpms/pdftk.

Would you consider using pypdf (Python) or qpdf (C++ with Python bindings) instead?

@svenssonaxel
Copy link
Owner

Thank you for the information, I had no idea that pdftk was problematic. I'll try out the alternatives you suggested.

svenssonaxel added a commit that referenced this issue Aug 16, 2023
@svenssonaxel
Copy link
Owner

@rocketraman If you want to help with testing, see branch issue-5

@rocketraman
Copy link
Author

@svenssonaxel Tried out the issue-5 branch but doesn't see to be working very well for me. The window that opens first shrinks down to a very small size, then the signature is shown in the middle of the first page. None of the controls to move the signature or navigate through pages work.

I'm using KDE on Fedora 38.

svenssonaxel added a commit that referenced this issue Jun 2, 2024
svenssonaxel added a commit that referenced this issue Jun 2, 2024
@svenssonaxel
Copy link
Owner

@rocketraman Could you please try branch issue-5 again?

svenssonaxel added a commit that referenced this issue Jun 3, 2024
@rocketraman
Copy link
Author

@rocketraman Could you please try branch issue-5 again?

Hi @svenssonaxel ! Pretty much the same as before. I see this error on startup:

/home/raman/opt/bin/pdf-sign:437: SyntaxWarning: invalid escape sequence '\('
[ignored, w, h, *ignored2]=fromCmdOutput(['pdfinfo', filePath], '^.*\nPage size: +([0-9.]+) x ([0-9.]+) pts( \([A-Za-z0-9]+\))?\n.*$')

After startup the window is quite small. The signature is in the middle and cannot be moved as far as I can tell. I also cannot navigate through the pages.

If I actually try to save the signature, it writes out a file, but page 3 of my 3 page PDF has been replaced by page 1 with my signature in the middle of the page.

@svenssonaxel
Copy link
Owner

@rocketraman I'd like some version information to try to reproduce this.

python3 --version
which -a python3 gs qpdf pdftk pdfinfo
gs --version
qpdf --version
pdftk --version
pdfinfo --help 2>&1|head -n 1
python3 -m tkinter

@rocketraman
Copy link
Author

@svenssonaxel :

@rocketraman I'd like some version information to try to reproduce this.

python3 --version

Python 3.12.3

which -a python3 gs qpdf pdftk pdfinfo

which: no pdftk in (...)
/usr/bin/python3
/bin/python3
/home/raman/.linuxbrew/bin/python3
/home/raman/.linuxbrew/bin/python3
/usr/bin/gs
/bin/gs
/usr/bin/qpdf
/bin/qpdf
/usr/bin/pdfinfo
/bin/pdfinfo

gs --version

10.02.1

qpdf --version

qpdf version 11.6.4
Run qpdf --copyright to see copyright and license information.

pdftk --version

fish: Unknown command: pdftk

pdfinfo --help 2>&1|head -n 1

pdfinfo version 23.08.0

python3 -m tkinter

image

@svenssonaxel
Copy link
Owner

@rocketraman
And your window manager and desktop environment?

@rocketraman
Copy link
Author

@rocketraman And your window manager and desktop environment?

KDE Plasma 5.27.11 on X11.

@svenssonaxel
Copy link
Owner

@rocketraman I've tried with kwin 5.27.5, python 3.12.3, tkinter 8.6.13. I wasn't able to reproduce all of the issues, but I'd still like you to pull branch issue-5 and try again.

  • The window that opens first shrinks down to a very small size: I wasn't able to reproduce with the current code, but I have replaced the relevant logic to something I believe should be more stable.
  • None of the controls to move the signature or navigate through pages work.: I was able to reproduce and fix the page navigation problem. I was not able to reproduce any problem moving the signature, except that it can take a moment, depending on how complex the page is.
  • If I actually try to save the signature, it writes out a file, but page 3 of my 3 page PDF has been replaced by page 1 with my signature in the middle of the page.: Should be fixed.

@rocketraman
Copy link
Author

rocketraman commented Jul 2, 2024

Thanks for the new drop. I'm on KDE Plasma 6.1.1 on Wayland now (after many years of trying Wayland every year and then giving up, I'm finally staying on Wayland this year!).

Other updated versions (if not listed here, its the same version as before):

  • qpdf is now 11.9.1
  • pdfinfo is now 24.02.0
  • Tcl/Tk 8.6.13

I've given the latest issue-5 branch a try.

  • The window size that opens is still quite small, but it is now at least usable. I see its running through XWayland, so the "Legacy applications (X11): Apply scaling themselves" setting in KDE might be relevant. My displays are 3840x2160 and scaled at 130%. The menu controls are scaled appropriately -- its just the window size that isn't optimal.
  • I can now navigate through pages. Its very slow but works. It takes about 2s to switch between pages.
  • I cannot move the signature at all, either by clicking or using the arrow keys. Enlarging and shrinking works.
  • Saving the signed PDF does now work.

@svenssonaxel
Copy link
Owner

The window is hard-coded to open with 800x600 geometry, intended to be small enough to fit on pretty much all screens. It should be possible to resize it though. Does resizing work for you?

I'm glad page navigation works. The 2s to switch between pages is due to the hacky way a page is shown; it is extracted from the source pdf using qpdf, then converted to an image and lastly loaded. If the pdf or page is complex/large, or the temporary file system is slow, this will take some time. I don't think I'll improve this much in the foreseeable future.

I do want to fix the key presses and clicks, though. I've now pushed a debug version. Could you try some key presses and clicks, and send me the output? Thanks!

@rocketraman
Copy link
Author

rocketraman commented Jul 4, 2024

The window is hard-coded to open with 800x600 geometry, intended to be small enough to fit on pretty much all screens. It should be possible to resize it though. Does resizing work for you?

That's really small for modern screens, especially high-DPI ones. But yes, it is resizable.

I'm glad page navigation works. The 2s to switch between pages is due to the hacky way a page is shown; it is extracted from the source pdf using qpdf, then converted to an image and lastly loaded. If the pdf or page is complex/large, or the temporary file system is slow, this will take some time. I don't think I'll improve this much in the foreseeable future.

My test PDF is 3 pages, 580kb. Large, but not huge. The temp filesystem is tmpfs backed by NVMe SSDs (and I have plenty of memory so it should never even see the SSD), so it should be pretty quick. For inspiration, maybe you could look at the way pdfarranger does it. In any case, this isn't a huge deal.

I do want to fix the key presses and clicks, though. I've now pushed a debug version. Could you try some key presses and clicks, and send me the output? Thanks!

Here is the output:

Debug: in dbg(event) for root <KeyPress>: char=, delta=0, height=??, keycode=64, keysym=Alt_L, keysym_num=65513, num=??, send_event=False, serial=676, state=16, time=122153149, type=2, widget=., width=??, x=261, x_root=5619, y=72, y_root=851
Debug: in onclick(event): char=??, delta=0, height=??, keycode=??, keysym=??, keysym_num=??, num=1, send_event=False, serial=4643, state=16, time=122163360, type=4, widget=.!canvas, width=??, x=991, x_root=6003, y=1268, y_root=1417
Debug: in dbg(event) for root <Button>: char=??, delta=0, height=??, keycode=??, keysym=??, keysym_num=??, num=1, send_event=False, serial=4643, state=16, time=122163360, type=4, widget=.!canvas, width=??, x=991, x_root=6003, y=1268, y_root=1417
Debug: in onclick(event): char=??, delta=0, height=??, keycode=??, keysym=??, keysym_num=??, num=1, send_event=False, serial=5038, state=16, time=122165356, type=4, widget=.!canvas, width=??, x=393, x_root=5405, y=1427, y_root=1576
Debug: in dbg(event) for root <Button>: char=??, delta=0, height=??, keycode=??, keysym=??, keysym_num=??, num=1, send_event=False, serial=5038, state=16, time=122165356, type=4, widget=.!canvas, width=??, x=393, x_root=5405, y=1427, y_root=1576
Debug: in onclick(event): char=??, delta=0, height=??, keycode=??, keysym=??, keysym_num=??, num=1, send_event=False, serial=5471, state=16, time=122169100, type=4, widget=.!canvas, width=??, x=237, x_root=5249, y=473, y_root=622
Debug: in dbg(event) for root <Button>: char=??, delta=0, height=??, keycode=??, keysym=??, keysym_num=??, num=1, send_event=False, serial=5471, state=16, time=122169100, type=4, widget=.!canvas, width=??, x=237, x_root=5249, y=473, y_root=622
Debug: in onkey(event): char=, delta=0, height=??, keycode=116, keysym=Down, keysym_num=65364, num=??, send_event=False, serial=5472, state=16, time=122170656, type=2, widget=., width=??, x=652, x_root=5659, y=903, y_root=1047
Debug: in onkey(event): char=, delta=0, height=??, keycode=116, keysym=Down, keysym_num=65364, num=??, send_event=False, serial=5854, state=16, time=122171426, type=2, widget=., width=??, x=652, x_root=5659, y=903, y_root=1047
Debug: in onkey(event): char=, delta=0, height=??, keycode=116, keysym=Down, keysym_num=65364, num=??, send_event=False, serial=5854, state=16, time=122171896, type=2, widget=., width=??, x=652, x_root=5659, y=903, y_root=1047
Debug: in onkey(event): char=, delta=0, height=??, keycode=114, keysym=Right, keysym_num=65363, num=??, send_event=False, serial=6570, state=16, time=122175756, type=2, widget=., width=??, x=652, x_root=5659, y=903, y_root=1047
Debug: in onkey(event): char=, delta=0, height=??, keycode=114, keysym=Right, keysym_num=65363, num=??, send_event=False, serial=6904, state=16, time=122176618, type=2, widget=., width=??, x=652, x_root=5659, y=903, y_root=1047
Debug: in onkey(event): char=, delta=0, height=??, keycode=114, keysym=Right, keysym_num=65363, num=??, send_event=False, serial=6904, state=16, time=122177203, type=2, widget=., width=??, x=652, x_root=5659, y=903, y_root=1047
Aborted

@svenssonaxel
Copy link
Owner

That's really small for modern screens, especially high-DPI ones. But yes, it is resizable.

Made it adaptive, does that feel better?

it should be pretty quick.

I've sped up the startup, at least on my side, and also added debug prints to find out what is taking so long on your side.

Could you try some key presses and clicks

Here is the output:

This is a little mysterious; I see nothing wrong in this output. I've pushed a heavier load of debug prints. Could you please

  • Try it out as it is, with clicking and arrow keys. Make sure to wait a good while, up to 10s, in case it's just very slow.
  • If the signature really does not change position, look through the debug output for the latest mention of temporary files ...signature-positioned.pdf and ...display.png. Open them and see in which ones the signature is correct.
  • Send me the output for a similar session as your last one. It's going to be more output this time, so you might want to pipe it.

@rocketraman
Copy link
Author

Made it adaptive, does that feel better?

Yes!

it should be pretty quick.

I've sped up the startup, at least on my side, and also added debug prints to find out what is taking so long on your side.

Could you try some key presses and clicks

Here is the output:

This is a little mysterious; I see nothing wrong in this output. I've pushed a heavier load of debug prints. Could you please

  • Try it out as it is, with clicking and arrow keys. Make sure to wait a good while, up to 10s, in case it's just very slow.
  • If the signature really does not change position, look through the debug output for the latest mention of temporary files ...signature-positioned.pdf and ...display.png. Open them and see in which ones the signature is correct.

I'm not sure what I'm looking for here... ...signature-positioned.pdf is just a 60x40mm blank PDF with my signature positioned exactly in the middle. And ...display.png is the entire page with the signature in the original location (the center).

  • Send me the output for a similar session as your last one. It's going to be more output this time, so you might want to pipe it.

output.txt

@svenssonaxel
Copy link
Owner

svenssonaxel commented Jul 14, 2024

Thank you, I might've found the issue, but not yet solved it.

Some pdf signatures work but not others. I have attached good-signature.pdf and bad-signature.pdf. On my machine,

  • They look identical when opened in a PDF reader
  • When used as a signature with pdf-sign, good-signature.pdf works as expected. It is possible to position it with both pointer clicks and arrow keys. When pressing S, the signature is located in the correct position in the resulting pdf.
  • When used as a signature with pdf-sign, bad-signature.pdf exhibits the behavior you describe. It is positioned in the middle and cannot be moved. Pressing S produces a pdf looking like what was shown, with the signature in the middle.

Can you confirm that all of the above is the case for you as well?

bad-signature.pdf
good-signature.pdf

@rocketraman
Copy link
Author

@svenssonaxel Yes, I can confirm the same behavior on my machine for bad-signature.pdf and good-signature.pdf.

@svenssonaxel
Copy link
Owner

Fixed on my side, can you confirm that everything is working for you now?

@rocketraman
Copy link
Author

Yes it works!

@svenssonaxel
Copy link
Owner

@rocketraman Thanks for all your help. Feel free to open new issues for any remaining concerns.

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

2 participants