qpdf icon indicating copy to clipboard operation
qpdf copied to clipboard

Text Selection Misalignment Issue with Chinese Characters in PDF

Open BigBrotherHui opened this issue 9 months ago • 4 comments

When loading a PDF, if the document contains Chinese text, the highlighted area does not align correctly with the actual text when selecting it using the left mouse button.

Image

BigBrotherHui avatar Apr 21 '25 08:04 BigBrotherHui

This is probably an issue of Qt5's web engine or pdf.js itself. This project uses pdf.js 2.0.550 (the current version is 5.1.91, but the recent versions is annoyingly difficult to integrate with Qt5 WebEngine). You may consider switching to Qt6 and use their pdf widget: https://doc.qt.io/qt-6/qtpdf-pdfviewer-example.html

Archie3d avatar Apr 21 '25 12:04 Archie3d

Thank you. When creating this PDF, using different font families leads to different display effects. Currently, when displaying Chinese text rendered by Microsoft YaHei, the selected area and the text are basically matched. However, there are version issues with Microsoft YaHei. Also, when the program calls this DLL in the form of a dynamic library, it seems that the DLL is not released properly after the program ends. Does this involve issues with QWebEngine or pdf.js? Is there anything additional that needs to be done? Thank you.

BigBrotherHui avatar Apr 22 '25 00:04 BigBrotherHui

This is probably due to the font metrics being calculated incorrectly by the the QWebEngine. What do you mean by the DLL not being released properly, how does this manifest itself? Does the progam crash when you close it? You may try compiling qpdf as a static library (*.lib) instead of a DLL.

Archie3d avatar Apr 22 '25 09:04 Archie3d

Okay, I’ll try compiling it as a static library later. Currently, the issue is that after I use the qpdf module once, then close the program and try to use the qpdf module again, the program becomes unresponsive. It doesn’t crash, but nothing happens — CPU and memory usage remain normal. It seems like the qpdfwidget just fails to display properly.

BigBrotherHui avatar Apr 23 '25 01:04 BigBrotherHui