Skip to content

Instantly share code, notes, and snippets.

@oxplot
Last active November 25, 2022 11:27
Show Gist options
  • Save oxplot/4b5ded9875cbba3e514f to your computer and use it in GitHub Desktop.
Save oxplot/4b5ded9875cbba3e514f to your computer and use it in GitHub Desktop.
Add hyperlinks to PDFs created by Inkscape
@Gaibhne
Copy link

Gaibhne commented Nov 24, 2022

Addendum: links are added correctly, but internal links to other pages don't work, because the objects presumably get optimized away due to not being on any page. Internal links to same-page elements produce a clickable link which work correctly (zooming in and clicking scrolls you to the target element). External links also work.

@Gaibhne
Copy link

Gaibhne commented Nov 24, 2022

Debugging shows that after # Load object IDs of all pages in the PDF document., only a single ID is found (earlier, under # Get pages and convert all measurements to pixels. all pages are correctly detected). The QDF output also shows only a single /Page, which I do not understand, especially not why it would work for you and not me. Inkscape Save Copy As correctly produces a multi-page-pdf. I'd be happy to supply files generated by me to test with but I'm not sure how to attach them here.

@oxplot
Copy link
Author

oxplot commented Nov 24, 2022

I'd be happy to supply files generated by me to test with but I'm not sure how to attach them here.

Yep, please do. You can upload your file here for e.g.: https://www.file.io/

@oxplot
Copy link
Author

oxplot commented Nov 24, 2022

Meanwhile, make sure you have your version of qpdf is not too far off of 11.1.1. Similarly, my Inkscape is at version Inkscape 1.2.1 (there seems to be a bunch of fixes for PDF export in 1.2.1 release).

@Gaibhne
Copy link

Gaibhne commented Nov 24, 2022

Oh God, I hope you didn't waste too much time on this yet. I just tested, and I did in fact have a broken Inkscape version because my upstream hadn't added the newest one yet. I got it working (although I have a file that I can't get working even after deleting every single thing in it, which I'll attach in case it's something obvious). But following your demo works perfectly for me now, so thanks!

Broken file: https://file.io/TF3IUwiLb3H1 - it's just three blank pages now, I've removed everything, but something makes the script error out with:

Traceback (most recent call last):
  File "/home/stoever/svglinkify-new/svglinkify.py", line 340, in <module>
    main()
  File "/home/stoever/svglinkify-new/svglinkify.py", line 70, in main
    svg_width_pixels = unit_2_px[svg_width[-2:]] * float(svg_width[:-2])
KeyError: '04'

@oxplot
Copy link
Author

oxplot commented Nov 24, 2022

Thanks for that. Was handling the px unit for the document size incorrectly. Just pushed a commit which works with your example file.

@Gaibhne
Copy link

Gaibhne commented Nov 24, 2022

It did, thank you again! Do you have one of those 'buy a developer a beer' kind of things ?

@oxplot
Copy link
Author

oxplot commented Nov 24, 2022

It did, thank you again! Do you have one of those 'buy a developer a beer' kind of things ?

Great. You're welcome - it was fun. I added some sponsor links to the svglinkify project page. :)

@Gaibhne
Copy link

Gaibhne commented Nov 25, 2022

I tried them all, and they are all too unconfigured to do anything :D Ko-Fi for example says "Oops, that didn't work! This creator cannot receive PayPal payments at this time.", and the others are all similar messages.

@oxplot
Copy link
Author

oxplot commented Nov 25, 2022

@Gaibhne whoops I should probably set them up 😄

EDIT: OMG, the payment part is a PITA — I guess I'm content with gratitude alone. Thanks anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment