fix(print): use pdftocairo to convert linearized PDF for printing#239
Merged
deepin-bot[bot] merged 2 commits intolinuxdeepin:masterfrom Jan 22, 2026
Merged
fix(print): use pdftocairo to convert linearized PDF for printing#239deepin-bot[bot] merged 2 commits intolinuxdeepin:masterfrom
deepin-bot[bot] merged 2 commits intolinuxdeepin:masterfrom
Conversation
remove excessive qCDebug/qCInfo calls in CentralDocPage, DocSheet and AttrScrollWidget that were likely used for debugging purposes but are not needed in production code
Replace custom Document API approach with pdftocairo process for better print quality and to resolve character encoding issues. The new method converts Linearized PDFs to embedded vector PDF format before printing. Log: fix pdf printing issue. Bug: https://pms.uniontech.com/bug-view-348017.html
deepin pr auto review这段代码的修改主要涉及三个方面:日志输出的移除、打印逻辑的重构以及事件过滤器的日志调整。以下是针对这三个方面的详细审查意见: 1. 日志输出调整 (CentralDocPage.cpp & AttrScrollWidget.cpp)修改内容: 审查意见:
2. 打印逻辑重构 (DocSheet.cpp)修改内容: 审查意见:
综合改进建议代码示例 (针对 DocSheet.cpp 打印部分)为了解决性能、安全和文件名冲突问题,建议修改如下: #include <QTemporaryFile>
#include <QProcess>
#include <QThread>
// ... 在 onPopPrintDialog 函数中 ...
if (Dr::PDF == fileType()) {
QString pdfPath = filePath();
// 1. 使用 QTemporaryFile 自动管理唯一的临时文件名和生命周期
// 注意:QTemporaryFile 创建后文件名即为空,需要 open() 一下,或者使用 template 构造
QTemporaryFile tmpFile;
tmpFile.setAutoRemove(false); // 我们需要把路径传给打印组件,暂时不能让Qt自动删
if (!tmpFile.open()) {
qCWarning(appLog) << "Failed to create temp file for print conversion.";
return;
}
QString tmpPdfPath = tmpFile.fileName();
tmpFile.close(); // 关闭句柄,只保留路径,pdftocairo 会覆盖写入
// 2. 启动进程,建议异步处理,这里仅展示同步写法的改进,实际项目中请务必异步化
QProcess process;
// 使用 -q 静默模式减少不必要的输出
process.start("pdftocairo", QStringList() << "-pdf" << "-q" << pdfPath << tmpPdfPath);
// 增加超时机制,防止永久阻塞(例如 30 秒)
if (!process.waitForFinished(30000)) {
qCWarning(appLog) << "pdftocairo timeout or crashed:" << process.errorString();
// 可选:清理残留文件
QFile::remove(tmpPdfPath);
return;
}
if (process.exitCode() != 0) {
qCWarning(appLog) << "pdftocairo failed:" << process.readAllStandardError();
// 可选:清理残留文件
QFile::remove(tmpPdfPath);
return;
}
preview->setPrintFromPath(tmpPdfPath);
// 3. 注意:这里需要确保 tmpPdfPath 在打印任务完成后被删除。
// 这可能需要在打印结束的回调槽函数中处理,或者依赖系统临时目录清理机制。
}总结这段代码移除高频日志是正确的优化,但打印逻辑的改动引入了 UI 阻塞、外部依赖和临时文件管理的问题。建议重点优化 |
lzwind
approved these changes
Jan 22, 2026
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lzwind, re2zero The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Contributor
Author
|
/merge |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace custom Document API approach with pdftocairo process for better
print quality and to resolve character encoding issues. The new method
converts Linearized PDFs to embedded vector PDF format before printing.