1

Topic: Python script for generate cross-references in .pdf file

Hello everybody!

In the company where I work, Faramax, we have created (with the help of AI, because we are not code programmers), this program in Phyton to create links between references in a .pdf file
This is a stopgap while the integrated function in QET is being developed, which would be great. Wish we could help with this, but as I said we are not programmers.
We have based it on this, but I prefer to create a new topic so we don't mix up the posts: https://qelectrotech.org/forum/viewtopic.php?id=2915

This program have calibration and adjustment options. It does not acquire the positions of the QET elements, but creates a virtual grid that must be adjusted with the row, column and px values that it adjusts in the QET sheets.
Alse, the program have additional offset settings for fine tuning.

When the program finds a relation to the selected structure, it creates a link to the target page and grid position, with the selected settings and zoom.

Attached you can find the programme in .py and in a ready for windows .exe inside the .rar

Hopefully this tool will be useful to many people, until QET integrates the function to include the links in the exported pdf.

I would also like to thank the developers of this fantastic tool that helps a lot of people.

BR,
Alfonso.

Post's attachments

Attachment icon GNerador_PDFLink.rar 90.17 mb, 27 downloads since 2025-06-16 

Attachment icon GNerador_PDFLink_v1.py 26.09 kb, 34 downloads since 2025-06-16 

Attachment icon Incterface.png 29.01 kb, file has never been downloaded. 

Attachment icon Interface_sett.png 35.27 kb, 1 downloads since 2025-06-16 

Attachment icon ScSh.png 7.14 kb, file has never been downloaded. 

Attachment icon test_linked.pdf 316.31 kb, 40 downloads since 2025-06-16 

2

Re: Python script for generate cross-references in .pdf file

I have tested the tool
I changed the settings to comply to my pages format

the tool finds 99 links but only 4 links created
they are on page 50

but the links are not going to the correct page
so what is the trick to make it working?

Post's attachments

Attachment icon ES EXAMPLE3.pdf 150.62 kb, 25 downloads since 2025-06-19 

Attachment icon ES EXAMPLE3.qet 2.82 mb, 17 downloads since 2025-06-19 

Attachment icon ES EXAMPLE3_linked.pdf 150.41 kb, 21 downloads since 2025-06-19 

Always using the latest development version

3

Re: Python script for generate cross-references in .pdf file

@LievenC: show your report link format!

Selected PDF: Z:/test_pdf_link.pdf
PDF test_pdf_link.pdf opened (55 pages)
Links detected: 245
Links created: 195
Linked PDF saved to:
Z:/test_pdf_link_linked.pdf

Post's attachments

Attachment icon test_pdf_link_linked.pdf 1.09 mb, 13 downloads since 2025-06-20 

"Le jour où tu découvres le Libre, tu sais que tu ne pourras jamais plus revenir en arrière..."Questions regarding QET belong in this forum and will NOT be answered via PM! – Les questions concernant QET doivent être posées sur ce forum et ne seront pas traitées par MP !

4

Re: Python script for generate cross-references in .pdf file

Minor changes,

use entire page.
rest offsetX to 0
set highlight link and border

Post's attachments

Attachment icon test_pdf_link_linked.2pdf.pdf 1.48 mb, 20 downloads since 2025-06-20 

"Le jour où tu découvres le Libre, tu sais que tu ne pourras jamais plus revenir en arrière..."Questions regarding QET belong in this forum and will NOT be answered via PM! – Les questions concernant QET doivent être posées sur ce forum et ne seront pas traitées par MP !

5

Re: Python script for generate cross-references in .pdf file

Hi LivenC,
The program looks for the texts with the format you set in the configuration (reference format) and creates a link to the corresponding page and zone of the .pdf
Your file has 20 sheets, so it is impossible to create links on sheet 50 for example.
I understand that in an electrical diagram the number of the printing sheet does not have to correspond to the name of the page, but this is not currently supported by the program.

Post's attachments

Attachment icon Screenshot.png 129.25 kb, 2 downloads since 2025-06-20 

6

Re: Python script for generate cross-references in .pdf file

The tool isn't perfect and needs more work, but it's the first one that's worked for me.nomicons/wink

"Le jour où tu découvres le Libre, tu sais que tu ne pourras jamais plus revenir en arrière..."Questions regarding QET belong in this forum and will NOT be answered via PM! – Les questions concernant QET doivent être posées sur ce forum et ne seront pas traitées par MP !

7

Re: Python script for generate cross-references in .pdf file

scorpio810 wrote:

The tool isn't perfect and needs more work, but it's the first one that's worked for me. nomicons/wink

I agree! And the best thing would be to include this functionality directly in QET built-in export tool.
We have little time to develop this tool.
Anyone can use the .py code and modify/improve it, if progress is made, please post it!

8

Re: Python script for generate cross-references in .pdf file

scorpio810 wrote:

The tool isn't perfect and needs more work, but it's the first one that's worked for me. nomicons/wink

no, it's not the first one to run. i'm already using my tool effectively with my first created plans.

9

Re: Python script for generate cross-references in .pdf file

@Kellermorph: have you tried this python program on Linux, or make an AppImage?

"Le jour où tu découvres le Libre, tu sais que tu ne pourras jamais plus revenir en arrière..."Questions regarding QET belong in this forum and will NOT be answered via PM! – Les questions concernant QET doivent être posées sur ce forum et ne seront pas traitées par MP !

10

Re: Python script for generate cross-references in .pdf file

The Program from Alfonos? No i didnt? Why are u asking?

11

Re: Python script for generate cross-references in .pdf file

I can now try Alfonso python  GNerador_PDFLink_v1.py under my Debian with:

pip uninstall fitz
pip install --upgrade --force-reinstall pymupdf

"Le jour où tu découvres le Libre, tu sais que tu ne pourras jamais plus revenir en arrière..."Questions regarding QET belong in this forum and will NOT be answered via PM! – Les questions concernant QET doivent être posées sur ce forum et ne seront pas traitées par MP !

12

Re: Python script for generate cross-references in .pdf file

did u build an appimage?

13

Re: Python script for generate cross-references in .pdf file

No, how do you use to build python program in an AppImage?

I tried nuitka and pyinstaller with no luck.

"Le jour où tu découvres le Libre, tu sais que tu ne pourras jamais plus revenir en arrière..."Questions regarding QET belong in this forum and will NOT be answered via PM! – Les questions concernant QET doivent être posées sur ce forum et ne seront pas traitées par MP !

14

Re: Python script for generate cross-references in .pdf file

u can do it with appimagetool.

I build an .sh with all.
you have to adjust the paths etc. in there.

Post's attachments

Attachment icon appimagetool-x86_64.AppImage 8.4 mb, 5 downloads since 2025-06-27 

Attachment icon build_appimage.sh 1.64 kb, 2 downloads since 2025-06-27 

15

Re: Python script for generate cross-references in .pdf file

I can build the AppImage in many VMs and they works well, but they don't work on other machines anymore.....

Traceback (most recent call last):
  File "/tmp/.mount_QET-ToJb3jVr/usr/lib/QET-Tools/GNerador_PDFLink_v1.py", line 19, in <module>
    import fitz  # PyMuPDF
    ^^^^^^^^^^^
ModuleNotFoundError: No module named 'fitz'

"Le jour où tu découvres le Libre, tu sais que tu ne pourras jamais plus revenir en arrière..."Questions regarding QET belong in this forum and will NOT be answered via PM! – Les questions concernant QET doivent être posées sur ce forum et ne seront pas traitées par MP !

16

Re: Python script for generate cross-references in .pdf file

i didnt know the Modul. It seems its not integrated.

if u look into my .sh file.

at point 4 he copy the venv. thats where the python moduls are. That has to be copyed too.

maybe the problem is because u did:

pip uninstall fitz
pip install --upgrade --force-reinstall pymupdf

and its not integrated it the venv.

17

Re: Python script for generate cross-references in .pdf file

Maybe take a look at my update
https://qelectrotech.org/forum/viewtopic.php?id=2938

there is the complete Code with the .sh and maybe its easyer to see how it works.

18

Re: Python script for generate cross-references in .pdf file

Same things, if you can try, I give up!!
It's a shame we can't share it here for Linux users.

https://stackoverflow.com/questions/564 … mupdf-fitz

"Le jour où tu découvres le Libre, tu sais que tu ne pourras jamais plus revenir en arrière..."Questions regarding QET belong in this forum and will NOT be answered via PM! – Les questions concernant QET doivent être posées sur ce forum et ne seront pas traitées par MP !

19

Re: Python script for generate cross-references in .pdf file

Linux Debian unstable binary.
https://download.qelectrotech.org/qet/s … ist.tar.gz

Extract archive GNerador_PDFLink_v1.dist.tar.gz and launch GNerador_PDFLink_v1.bin
(enlarge the window to see all buttons...)

Need GLIBC 2.38!



(venv) [10:52:27] laurent@debian:~$ nuitka --mode=standalone  --enable-plugin=tk-inter GNerador_PDFLink_v1.py 
Nuitka-Options: Used command line options:
Nuitka-Options:   --mode=standalone --enable-plugin=tk-inter GNerador_PDFLink_v1.py
Nuitka: Starting Python compilation with:
Nuitka:   Version '2.7.10' on Python 3.13 (flavor 'Debian Python') commercial grade 'not installed'.
Nuitka-Plugins:anti-bloat: Not including 'PIL.ImageQt' automatically in order to avoid bloat, but this may cause: PIL will not be able to create Qt image objects.
Nuitka-Plugins:anti-bloat: Not including 'pandas.core._numba.extensions' automatically in order to avoid bloat, but this may cause: no numba acceleration.
Nuitka-Plugins:anti-bloat: Not including 'lxml' automatically in order to avoid bloat, but this may cause: no stylesheet support in pandas.io.formats.xml without including lxml.
Nuitka: Completed Python level compilation and optimization.
Nuitka: Generating source code for C backend compiler.
Nuitka: Running data composer tool for optimal constant value handling.                                                      
Nuitka: Running C compilation via Scons.
Nuitka-Scons: Backend C compiler: gcc (gcc 14).
Nuitka-Scons: Slow C compilation detected, used 360s so far, scalability problem.
Nuitka-Scons: Running /usr/bin/ccache /usr/bin/gcc -o module.pymupdf.mupdf.o -c -std=c11 -fvisibility=hidden -fwrapv -pipe -Wno-unused-but-set-variable -fpartial-inlining -ftrack-macro-expansion=0 -Wno-deprecated-declarations -fno-var-tracking -Wno-misleading-indentation -fcompare-debug-second -fno-lto -O2 -D_NUITKA_STANDALONE_MODE -D_NUITKA_EXE_MODE -D_WIN32_WINNT=0x0601 -D__NUITKA_NO_ASSERT__ -DPy_NO_ENABLE_SHARED -D_NUITKA_STATIC_LIBPYTHON -D_NUITKA_USE_UNEXPOSED_API -D_NUITKA_INLINE_COPY_HACL -D_NUITKA_CONSTANTS_FROM_INCBIN -D_NUITKA_FROZEN=152 -D_NUITKA_PLUGIN_MULTIPROCESSING_ENABLED=1 -I~/venv/lib/python3.13/site-packages/nuitka/build/inline_copy/zlib -I/usr/include/python3.13 -I/usr/include/python3.13/internal/mimalloc -I~/venv/lib/python3.13/site-packages/nuitka/build/inline_copy/python_hacl/hacl_312 -I~/venv/lib/python3.13/site-packages/nuitka/build/inline_copy/python_hacl/hacl_312/include -I. -I~/venv/lib/python3.13/site-packages/nuitka/build/include -I~/venv/lib/python3.13/site-packages/nuitka/build/static_src -I~/venv/lib/python3.13/site-packages/nuitka/build/inline_copy/libbacktrace module.pymupdf.mupdf.c took 1114.89 seconds
Nuitka-Scons: Backend C linking with 973 files (no progress information available for this stage).
Nuitka-Scons: Compiled 972 C files using ccache.
Nuitka-Scons: Cached C files (using ccache) with result 'cache miss': 972
Nuitka-Plugins:data-files: Included data file 'jaraco/text/Lorem ipsum.txt' due to package data for 'jaraco.text'.
Nuitka-Plugins:data-files: Included data file 'pandas/io/formats/templates/html.tpl' due to package data directory 'templates' for 'pandas.io.formats'.
Nuitka-Plugins:data-files: Included data file 'pandas/io/formats/templates/html_style.tpl' due to package data directory 'templates' for 'pandas.io.formats'.
Nuitka-Plugins:data-files: Included data file 'pandas/io/formats/templates/html_table.tpl' due to package data directory 'templates' for 'pandas.io.formats'.
Nuitka-Plugins:data-files: Included data file 'pandas/io/formats/templates/latex.tpl' due to package data directory 'templates' for 'pandas.io.formats'.
Nuitka-Plugins:data-files: Included data file 'pandas/io/formats/templates/latex_longtable.tpl' due to package data directory 'templates' for 'pandas.io.formats'.
Nuitka-Plugins:data-files: Included data file 'pandas/io/formats/templates/latex_table.tpl' due to package data directory 'templates' for 'pandas.io.formats'.
Nuitka-Plugins:data-files: Included data file 'pandas/io/formats/templates/string.tpl' due to package data directory 'templates' for 'pandas.io.formats'.
Nuitka-Plugins:data-files: Included 604 data files due to package data directory 'zoneinfo' for 'pytz'.
Nuitka-Plugins:data-files: Included data file 'scipy/stats/_sobol_direction_numbers.npz' due to package data for 'scipy'.
Nuitka-Plugins:tk-inter: Included 71 data files due to Tk needed for tkinter usage.
Nuitka-Plugins:tk-inter: Included 262 data files due to Tcl needed for tkinter usage.
Nuitka: Keeping build directory 'GNerador_PDFLink_v1.build'.
Nuitka: Successfully created 'GNerador_PDFLink_v1.dist/GNerador_PDFLink_v1.bin'.
(venv) [11:43:10] laurent@debian:~$ 

"Le jour où tu découvres le Libre, tu sais que tu ne pourras jamais plus revenir en arrière..."Questions regarding QET belong in this forum and will NOT be answered via PM! – Les questions concernant QET doivent être posées sur ce forum et ne seront pas traitées par MP !

20

Re: Python script for generate cross-references in .pdf file

I will take a look if i can make an appimage. but it will take a some time before i have time to do that.

21

Re: Python script for generate cross-references in .pdf file

The app image is attached. I could not upload the folder structure and the .sh file to create an appimage because it is too big (262MB)
Unfortunately I could not test the function because my format of cross-references is not supported.
I am using Y.X. (page.column)
Alfonso could you add this function?

Post's attachments

Attachment icon GNerador_PDF_Link-x86_64.AppImage 44.15 mb, 2 downloads since 2025-06-29 

22

Re: Python script for generate cross-references in .pdf file

Trried on Ubuntu 22.04

./GNerador_PDF_Link-x86_64.AppImage
[PYI-3413:ERROR] Failed to load Python shared library '/tmp/_MEI0ZA41v/libpython3.12.so.1.0': /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.38' not found (required by /tmp/_MEI0ZA41v/libpython3.12.so.1.0)

Also your AppImage work weel on my Debian unstable, thanks you. nomicons/wink


Yesterday I tried to build binary on many old Linux VM (Debian 11 Debian 12, Ubuntu 22.04), for GLIBC compatibility but no luck...

nuitka make some hours to compile the binary and crash at the end on Scons error...

"Le jour où tu découvres le Libre, tu sais que tu ne pourras jamais plus revenir en arrière..."Questions regarding QET belong in this forum and will NOT be answered via PM! – Les questions concernant QET doivent être posées sur ce forum et ne seront pas traitées par MP !

23

Re: Python script for generate cross-references in .pdf file

I am using Y.X. (page.column)

Why not use rows, it 's was better for search X ref?

"Le jour où tu découvres le Libre, tu sais que tu ne pourras jamais plus revenir en arrière..."Questions regarding QET belong in this forum and will NOT be answered via PM! – Les questions concernant QET doivent être posées sur ce forum et ne seront pas traitées par MP !

24

Re: Python script for generate cross-references in .pdf file

On macOS is the same things:

wget https://qelectrotech.org/forum/misc.php?action=pun_attachment&item=3382&download=1
pip3 install fitz
pip3 install pymupdf
pip3 install ttkbootstrap
python3 GNerador_PDFLink_v1.py

"Le jour où tu découvres le Libre, tu sais que tu ne pourras jamais plus revenir en arrière..."Questions regarding QET belong in this forum and will NOT be answered via PM! – Les questions concernant QET doivent être posées sur ce forum et ne seront pas traitées par MP !