fix(print): use pdftocairo to convert linearized PDF for printing#241
Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:release/eaglefrom Jan 26, 2026
Merged
Conversation
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这段代码主要是为了解决 PDF 打印时的乱码和模糊问题,将原来的“Linearized PDF 检测并转换”逻辑替换为“强制使用 以下是对该 1. 语法逻辑
2. 代码质量
3. 代码性能
4. 代码安全
代码重构建议综合以上意见,建议修改后的代码逻辑如下: //pdf若是Linearized类型的,需要另存为Normal类型,然后打印
if (Dr::PDF == fileType()) {
QString pdfPath = filePath();
// 使用 pdftocairo 转换为嵌入矢量pdf,解决打印乱码和模糊问题
// 1. 构造唯一的临时文件路径
QString tmpPdfPath = convertedFileDir() + "/pdftocairoPrint_" + QString::number(QDateTime::currentMSecsSinceEpoch()) + ".pdf";
// 2. 检查命令是否存在 (可选,视具体部署环境而定,或者直接捕获错误)
QProcess process;
// 3. 启动转换
// 建议添加 -q (quiet) 参数减少不必要的控制台输出
process.start("pdftocairo", QStringList() << "-pdf" << "-q" << pdfPath << tmpPdfPath);
// 4. 等待完成,设置 30 秒超时
if (!process.waitForFinished(30000)) {
qWarning() << "pdftocairo timeout or crashed:" << process.errorString();
process.kill();
process.waitForFinished();
return; // 或者考虑回退逻辑:直接使用 pdfPath
}
// 5. 检查退出码
if (process.exitCode() != 0) {
QString err = process.readAllStandardError();
qWarning() << "pdftocairo failed with exit code" << process.exitCode() << ":" << err;
// 安全建议:如果转换失败,是否应该回退到直接打印原文件?
// preview->setPrintFromPath(pdfPath);
return;
}
qInfo() << "pdftocairo convert success, saved to:" << tmpPdfPath;
preview->setPrintFromPath(tmpPdfPath);
// 注意:需要在合适的地方(如析构或打印结束)添加 QFile::remove(tmpPdfPath);
} |
max-lvs
approved these changes
Jan 26, 2026
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: LiHua000, max-lvs 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
|
/forcemerge |
Contributor
|
This pr force merged! (status: unstable) |
9cdbe75
into
linuxdeepin:release/eagle
5 of 6 checks passed
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.
Log: fix pdf printing issue.
Bug: https://pms.uniontech.com/bug-view-348017.html
cherry-pick to: https://pms.uniontech.com/bug-view-348169.html