Re: Functional Cross-Reference in PDF
Still this warning:
Warning! The following errors must be corrected before your message can be posted:
The selected file was too large to upload. The server didn't allow the upload.
You are not logged in. Please login or register.
QElectroTech → Code → Functional Cross-Reference in PDF
Still this warning:
Warning! The following errors must be corrected before your message can be posted:
The selected file was too large to upload. The server didn't allow the upload.
Problem is on server return -> 413 Request Entity Too Large
So put your code to github, and create tag after you can import big files under the tag, I don't know the limit size?
i got a bit of time. Here is the link
https://github.com/Kellermorph/QuerverweiseAppImage
i hope that i've done evertything right and it's working. It's my first time.
Please put your code on Github if you can, for us it's more esay to see which code changes!
It is very easy if you have git, ssh, etc on your setup, but I remenber you use macOS, so no problem!
On Terminal get your github repository
git clone https://github.com/Kellermorph/QuerverweiseAppImage.gitNow work in QuerverweiseAppImage folder with your IDE as usual,
but if you want use terminal:
for adding files or files changed use
git add file_name git diffwhat files was added or removed.
- it is removed
+ it is added
For upload your changes to your online Github branch, it's very easy.
git pushFor refreshing your local repository.
git pull
The Code ist there. Its called "Querverweise.py".
Or did i Miss understand Something?
Btw i'm using Linux Mint.
Or did i Miss understand Something?
Same for me ....,
in first you talk avout QET 's code, now I see a python file, it 's me or then I need to return to bed for rest?
I can reassure you, Laurent:
I understood that differently, too!
Maybe it's also due to my poor English. I apologize for that.
I had first tried the source code via chatgpt. That was not successful. PLC-User then asked me to compile the code myself and give it a try. But in my current situation this is too complicated / time-consuming. That's why I've been looking for an alternative that can at least temporarily help me and possibly some others. I have written a small Python program (with the help of ChatGPT), which searches a finished exported circuit diagram (PDF) for cross-references and then links them. However, only to the page and not directly to the component.
Translated with DeepL.com (free version)
@scorpio810:
(...) forgot to Refresh hooks in attachments plugin....I'm tired!!!
Something's wrong with the forums' attachments, Laurent!
This afternoon, I attached a file and it was marked as "not allowed to download"
And now I don't see any attachment in the forum!
@plc-user,
I was able to fix my error...I re-imported the attached files from the rsnapthot backup and on the server for SQL database with phpMyAdmin I re imported the old ‘punbb_attach_files’ table for recreate these ‘indexes!
But the last backup was made yesterday at 15h00, so please put again your script, many sorry.
@scorpio810:
It's not just about the Registry-script:
It seems that many attachments are lost somehow!
If you look at this post from 20. February:
https://qelectrotech.org/forum/viewtopi … 099#p21099
There should be a png as attachment, but there is only a link!
When I follow the link, it says:
Bad request. The link you followed is incorrect or outdated.Same here with post from 10. March
https://qelectrotech.org/forum/viewtopi … 220#p21220
Bad request. The link you followed is incorrect or outdated.
Auch, wenn Du den Text als Link markierst und den Text als Ziel-Adresse definieren kannst:
Das Ziel muss auch wissen, daß es Ziel ist, (...)
In the meantime, I have written a code that creates a position list with links and targets in the print module that can be used to insert PDF links.
I just haven't found anything in the Qt docs that explains what a link or a corresponding target should look like so that it works in the PDF file!
***** find positions for PDF-internal links...
XRef from page 3 QPoint(1380,620) to page 4 QPoint(120,440)
XRef from page 3 QPoint(1380,770) to page 4 QPoint(120,90)
XRef from page 3 QPoint(1380,640) to page 4 QPoint(120,420)
XRef from page 3 QPoint(1380,600) to page 4 QPoint(120,400)
XRef from page 3 QPoint(1380,790) to page 4 QPoint(120,110)
XRef from page 4 QPoint(120,90) to page 3 QPoint(1380,770)
XRef from page 4 QPoint(1320,90) to page 5 QPoint(120,90)
XRef from page 4 QPoint(120,110) to page 3 QPoint(1380,790)
XRef from page 4 QPoint(120,440) to page 3 QPoint(1380,620)
XRef from page 4 QPoint(1320,110) to page 5 QPoint(120,110)
XRef from page 4 QPoint(120,400) to page 3 QPoint(1380,600)
XRef from page 4 QPoint(120,420) to page 3 QPoint(1380,640)
XRef from page 5 QPoint(1380,90) to page 6 QPoint(120,90)
XRef from page 5 QPoint(120,90) to page 4 QPoint(1320,90)
XRef from page 5 QPoint(1380,110) to page 6 QPoint(120,110)
XRef from page 5 QPoint(120,110) to page 4 QPoint(1320,110)
XRef from page 6 QPoint(120,110) to page 5 QPoint(1380,110)
XRef from page 6 QPoint(1380,270) to page 8 QPoint(110,180)
XRef from page 6 QPoint(1380,440) to page 8 QPoint(110,440)
XRef from page 6 QPoint(1380,410) to page 8 QPoint(110,410)
XRef from page 6 QPoint(1380,240) to page 8 QPoint(110,210)
XRef from page 6 QPoint(120,90) to page 5 QPoint(1380,90)
XRef from page 8 QPoint(110,440) to page 6 QPoint(1380,440)
XRef from page 8 QPoint(110,180) to page 6 QPoint(1380,270)
XRef from page 8 QPoint(110,410) to page 6 QPoint(1380,410)
XRef from page 8 QPoint(110,210) to page 6 QPoint(1380,240)There are also additional constraints such as fitting on the page or the print area. "Automagic" zoom factors are used here, which also have to be applied to the positions of the links and targets.
Hallo plc-user!
You could share a patch?
Based on the qt6-make branch with some more cleanup regarding Qt version checks.
By the way: I have to take a closer look at git-branches. How to use them and so ...
Hello!
Are there any further developments on this?
I would like to leave a link to the post where I share a tool that generates the links in a .pdf automatically.
https://qelectrotech.org/forum/viewtopic.php?id=2982
We have built on what has been published in this post so far, and with the help of AI we have generated the tool.
I preferred to separate the posts so as not to mix up the tools.
Hopefully this can help in the development to integrate the function into QET!
Ich bin seit langem mit ChatGPT dran, und versuche die Verlinkung hinzubekommen.
Wir arbeiten auf dem Skript von PLC-User weiter.
Wir haben bereits den Erfolg, dass Rote Rechtecke reingezeichnet werden.
Hierbei fällt auf, dass diese nicht richtig positioniert werden. Die landen auf dem Bauteil und nicht auf dem Verweis.
Weiß jemand, wo die Koordinaten vom den Querverweis gespeichert ist, damit man diese übernehmen kann?
Translate:
I've been working with ChatGPT for a long time and am trying to get the link to work.
We are continuing to work on the PLC-User script.
We have already succeeded in drawing red rectangles.
However, it is noticeable that these are not positioned correctly. They end up on the component and not on the reference.
Does anyone know where the coordinates of the cross-reference are stored so that they can be transferred?
Translated with DeepL.com (free version)
Ich komme momentan mit Chatgpt echt nicht weiter.
Es hängt noch daran, dass der Querverweis vom Bauteil angehangen wird.
Momentan wird in der projectprintwindow.cpp noch verschiedene Sachen erkannt. Ich habe euch meinen aktuellen Stand mal angehangen.
Die blauen Rechtecke sind die, die schon passend auf den Slave-Querverweisen positioniert werden.
Möglicherweise hat noch jemand von euch eine Idee.
Damit ihr euch ein Bild machen könnt, habe ich auch ein kleines Projekt angehangen, womit ich das teste.
Translate:
I'm really stuck at the moment.
It still depends on the cross-reference being attached to the component.
At the moment, various things are still being recognized in projectprintwindow.cpp. I've attached my current status for you.
The blue rectangles are the ones that are already positioned correctly on the slave cross-references.
Maybe one of you has an idea.
To give you an idea, I've also attached a small project that I'm using to test this.
Translated with DeepL.com (free version)
@plc-user
Excellent work on the position list — this is exactly the right foundation. I can bring two missing pieces.
**1. The Qt API you were looking for: `QPdfEngine::drawHyperlink`**
The Qt PDF engine already supports link annotations internally via a private method:
```cpp
void QPdfEngine::drawHyperlink(const QRectF &r, const QUrl &url)
```
It is accessible (unofficially) by casting the paint engine after `diagram->render()`:
```cpp
#include <private/qpdf_p.h>
// After diagram->render(painter, ...) on each page:
if (printer->outputFormat() == QPrinter::PdfFormat) {
auto *pdfEngine = dynamic_cast<QPdfEngine*>(painter->paintEngine());
if (pdfEngine) {
// painter->worldTransform() captures the scale applied by render()
// Use it to map scene coordinates -> printer coordinates
QTransform t = painter->worldTransform();
for (auto &link : xrefLinksForThisPage) {
QRectF printerRect = t.mapRect(link.sourceRect);
QUrl target(QString("page=%1&x=%2&y=%3")
.arg(link.targetPage)
.arg(link.targetX)
.arg(link.targetY));
pdfEngine->drawHyperlink(printerRect, target);
}
}
}
```
This is private API (requires Qt private headers: `QT += gui-private` in .pro or `find_package(Qt6 ... PRIVATE)` in CMake), so it could theoretically change between Qt versions — but it has been present and stable since Qt 4 and is still there in Qt 6.11. QTBUG-44563 (open since 2015) tracks the request for a public API.
The `painter->worldTransform()` is the key to solving your zoom/fit_page problem: after each `diagram->render(painter, targetRect, sourceRect, Qt::KeepAspectRatio)`, the painter's world transform already encodes the exact scale and offset applied. Mapping the scene-space link rectangles through this transform gives the correct printer-space coordinates automatically.
**2. An important correctness issue: page number vs. folio label**
Using `page=N` as the link target works if folio order never changes. But QET supports two different ways to identify folios:
- `%f` — position in the tree (physical page number in the PDF). If the user reorders folios, all links break.
- `%F` — the folio label, stable regardless of position in the tree.
If users configure their XRef formulas with `%F` instead of `%f`, they expect links to follow the folio wherever it moves. A link based on `page=N` does not honour this.
The robust solution is to build a **named destination dictionary** before the print pass:
```
folio_label -> (physical_page_number, y_position)
```
Then use the label as the link target instead of the page number. Unfortunately `drawHyperlink` only accepts a `QUrl`, so named internal destinations would require writing raw PDF annotations — which means either a post-processing step (as Alfonso's Python script does) or a third-party library (libmupdf, QPDF).
For a pragmatic first implementation, `page=N` with `drawHyperlink` is a good start — it works correctly as long as the folio order at export time matches the XRef labels. Just worth documenting the limitation.
**Summary**
- `QPdfEngine::drawHyperlink` + `painter->worldTransform()` solves the injection and the coordinate scaling in one step
- Named destinations (for `%F` stability) require a post-processing pass or lib — this is a known limitation of what Qt exposes today
- Your position list code is the right foundation; the missing piece was just how to inject it
Happy to help test or integrate this if you share the patch.
Hallo Thomas wip, could you have a look at this patch based on the master branch (Qt5)? The links work, but it’s very difficult to find the good X and Y coordinates even with AI....
Hi Laurent,
I'm currently working on another feature, and after that I'll be going on vacation with my wife and kids. So unfortunately, I won't be able to get to it anytime soon.
Other than that, I only use AI (Gemini) for all my editing.
Have a lovely vacation, Thomas, and make the most of your time with the family, wife, and childrens. I didn’t get to see my sons grow up – time flies so quickly, and they’ve already overtaken me – but today, I’m amazed to see just how much my two adorable grandsons have grown – wow, they’re bursting with energy and are so clever and absolutely adorable. <3
Thank you very much. My father-in-law gave me the same advice, and I try to spend as much time with them as possible.
The new feature is available as a pull request on GitHub.
Once it's merged, I'll quickly add the German translation so that everything can be rolled out at once, including my previous pull request.
I've made a bit of progress; try this fix based on master branch:
Needs:
sudo apt install qtbase5-private-dev
QElectroTech → Code → Functional Cross-Reference in PDF
Powered by PunBB, supported by Informer Technologies, Inc.
Generated in 0.018 seconds (33% PHP - 67% DB) with 11 queries