Skip to content

feat(batch-print): add headless batch print for pdf/docx/djvu/xps - #384

Closed
pengfeixx wants to merge 1 commit into
masterfrom
feat/batch-print
Closed

pengfeixx wants to merge 1 commit into
masterfrom
feat/batch-print

Conversation

@pengfeixx

@pengfeixx pengfeixx commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

feat: add headless batch print for pdf/docx/djvu/xps

Summary

新增 deepin-reader-batchprint 独立进程,支持在文件管理器中多选 pdf/docx/djvu/xps 文档后通过右键菜单"批量打印"静默完成打印,全程无对话框交互。

Key changes

  • batch-print 模块:格式归一化(pdf 直通、docx 经 pandoc、djvu 300dpi 渲染、xps 导出)+ CUPS 运行时 dlopen 提交 + DBus 通知
  • PrintSettings 结构体:预留 DTK 打印设置接口,当前仅 copies/sides/ColorModel 安全子集映射为 CUPS 选项
  • 构建系统:CMakeLists.txt 集成 batch-print 子目录;linglong.yaml build 段切换为 CMake 构建;translation-generate.cmake 修复 lrelease 路径查找
  • 单元测试:printsettings/cupsclient/formatconverter/notifyclient 四个测试模块
  • 上下文菜单:新增 deepin-reader-batchprint.conf 注册右键菜单项

Test scenarios

  • 玲珑构建 ll-builder build 成功,batch-print 正确编出并打包
  • DOCX/PDF/DJVU/XPS 批量打印均正常提交到打印机
  • 退出码:0=全部成功、1=存在失败、2=环境错误

Related: V-4012

Summary by Sourcery

Introduce silent batch printing for supported document formats from the file manager while integrating the new executable into the CMake and packaging workflows.

New Features:

  • Add a headless batch-print executable that silently prints selected PDF, DOCX, DjVu, and XPS documents through the default printer.
  • Register a file-manager context-menu action for batch printing single or multiple supported documents.
  • Provide localized DBus notifications for successful, partial, failed, and environment-error outcomes.

Bug Fixes:

  • Improve installation-path resolution for helper binaries in multi-architecture environments.
  • Make translation generation locate Qt's lrelease executable across common runtime and system paths.

Enhancements:

  • Normalize supported document formats to PDF before submission and expose a print-settings model for copies, duplex, and color options.
  • Load CUPS dynamically and validate printer availability before submitting print jobs.
  • Add DjVu page resolution support for accurate rendered page sizing.

Build:

  • Integrate the batch-print target and context-menu installation into CMake, and migrate the Linglong build to CMake.

Tests:

  • Add optional unit-test coverage for print-option mapping, CUPS abstraction, format conversion, page geometry, and notification formatting.

Add deepin-reader-batchprint standalone process for multi-file batch
printing from file manager context menu without any dialog interaction.

新增无界面批量打印能力:文件管理器多选文档后右键"批量打印"
拉起独立进程静默完成打印,支持 pdf/docx/djvu/xps 格式。

Log: 新增deepin-reader批量打印功能
Influence: 用户可在文件管理器中多选文档批量打印,无需逐个操作。
@github-actions

Copy link
Copy Markdown
  • 检测到debian目录文件有变更: debian/control

@sourcery-ai

sourcery-ai Bot commented Sep 15, 2026

Copy link
Copy Markdown

Reviewer's Guide

This PR adds a file-manager-invoked, headless batch-print process that normalizes PDF/DOCX/DjVu/XPS documents, submits them to a default CUPS printer without linking CUPS at build time, reports aggregate results over DBus, and integrates the executable, context menu, multiarch packaging, and optional unit tests into the build.

Sequence diagram for headless batch document printing

sequenceDiagram
    actor User
    participant FileManager
    participant BatchPrintApp
    participant FormatConverter
    participant CupsClient
    participant CUPS
    participant NotifyClient
    participant DBus

    User->>FileManager: Select documents and choose Batch Print
    FileManager->>BatchPrintApp: deepin-reader-batchprint %F
    BatchPrintApp->>CupsClient: init()
    CupsClient->>CUPS: dlopen and resolve symbols
    BatchPrintApp->>CupsClient: checkEnvironment()
    CupsClient->>CUPS: get default printer
    loop Each input file
        BatchPrintApp->>FormatConverter: convertToPdf(filePath, tempDir)
        FormatConverter-->>BatchPrintApp: outputPdfPath
        BatchPrintApp->>CupsClient: submitJob(outputPdfPath, jobTitle, settings)
        CupsClient->>CUPS: cupsPrintFile()
        CUPS-->>CupsClient: job result
    end
    BatchPrintApp->>NotifyClient: notifyResult(total, succeeded, failedFiles)
    NotifyClient->>DBus: Notify()
    DBus-->>User: Aggregate print result
Loading

Flow diagram for document normalization before printing

flowchart LR
    Input["Selected PDF DOCX DjVu or XPS"] --> Detect["detectFileTypeWithFallback"]
    Detect --> PDF["PDF: use original file"]
    Detect --> DOCX["DOCX: DocumentFactory via pandoc"]
    Detect --> DJVU["DjVu: render pages at 300 DPI"]
    Detect --> XPS["XPS: doc->saveAs"]
    PDF --> Output["PDF input for CUPS"]
    DOCX --> Output
    DJVU --> Output
    XPS --> Output
    Output --> Submit["CupsClient.submitJob"]
Loading

File-Level Changes

Change Details Files
Adds a standalone headless batch-print executable that converts supported documents to PDF, submits jobs through dynamically loaded CUPS APIs, and reports outcomes through desktop notifications.
  • Introduces per-file conversion and temporary-directory lifecycle with exit codes for environment and file-level failures.
  • Loads required CUPS symbols at runtime, selects a default printer, queries color support, and maps copies/duplex/color settings to CUPS options.
  • Adds command-line file handling and offscreen Qt initialization for invocation from the file manager.
  • Adds success, partial-failure, and environment-error notification messages with failed-file truncation.
batch-print/batchprintapp.cpp
batch-print/batchprintapp.h
batch-print/cupsclient.cpp
batch-print/cupsclient.h
batch-print/icupsapi.h
batch-print/main.cpp
batch-print/notifyclient.cpp
batch-print/notifyclient.h
batch-print/errormessages.cpp
batch-print/errormessages.h
batch-print/printsettings.cpp
batch-print/printsettings.h
Implements format-specific PDF normalization for PDF, DOCX, DjVu, and XPS inputs while reusing selected reader document components.
  • Passes PDFs through unchanged and uses the existing document factory/pandoc path for DOCX conversion.
  • Renders DjVu pages at 300 DPI into PDFs while deriving page dimensions from source resolution.
  • Uses the XPS document adapter's saveAs path when XPS support is enabled.
  • Adds page resolution support to the reader page abstraction and DjVu implementation.
batch-print/formatconverter.cpp
batch-print/formatconverter.h
reader/document/Model.h
reader/document/Model.cpp
reader/document/DjVuModel.h
reader/document/DjVuModel.cpp
reader/CMakeLists.txt
Integrates batch printing into CMake, packaging, Linglong builds, and the file-manager context menu.
  • Builds separate batchprint-core and batchprint-convert static libraries plus the installed executable.
  • Installs the batch-print context-menu registration for supported MIME types and multi-file selection.
  • Switches the Linglong build recipe from qmake to CMake and updates multiarch library deployment paths.
  • Improves lrelease discovery and adds install-libdir handling for htmltopdf lookup.
CMakeLists.txt
batch-print/CMakeLists.txt
linglong.yaml
cmake/translation-generate.cmake
src/context-menus/deepin-reader-batchprint.conf
reader/CMakeLists.txt
reader/document/Model.cpp
Adds optional GoogleTest coverage for settings mapping, CUPS abstraction behavior, conversion helpers, and notification formatting.
  • Tests copies, duplex, and color option normalization including bounds handling.
  • Tests representative conversion validation and DjVu geometry calculations.
  • Tests notification text for success, failure, truncation, zero-file, and environment-error cases.
  • Adds an opt-in BATCH_PRINT_TESTS CMake switch and test targets.
batch-print/tests/CMakeLists.txt
batch-print/tests/ut_printsettings.cpp
batch-print/tests/ut_cupsclient.cpp
batch-print/tests/ut_formatconverter.cpp
batch-print/tests/ut_notifyclient.cpp
Updates packaging metadata to account for the new build/runtime dependencies.
  • Adjusts Debian control metadata for the batch-print feature and its dependencies.
debian/control

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="CMakeLists.txt" line_range="264-271" />
<code_context>

 if (USE_PDFIUM_BUNDLE)
     add_subdirectory(3rdparty/deepin-pdfium)
+    add_subdirectory(batch-print)
+
+    # Install context-menus (batch print)
+    install(FILES src/context-menus/deepin-reader-batchprint.conf
+            DESTINATION ${CMAKE_INSTALL_DATADIR}/applications/context-menus)
 endif()

 # 单元测试(可选)
</code_context>
<issue_to_address>
**issue (broader_impact):** The batch-print executable and its context-menu registration are only added when `USE_PDFIUM_BUNDLE` is enabled. Configurations that intentionally use the system PDFium library build the reader but omit the advertised batch-print feature entirely.

**Triggers:** When the project is configured with `-DUSE_PDFIUM_BUNDLE=OFF`.

**Suggested fix:** Move the batch-print subdirectory and context-menu installation outside the `USE_PDFIUM_BUNDLE` conditional; retain only the PDFium target selection inside the conditional.

```suggestion
if (USE_PDFIUM_BUNDLE)
    add_subdirectory(3rdparty/deepin-pdfium)
endif()

add_subdirectory(batch-print)

# Install context-menus (batch print)
install(FILES src/context-menus/deepin-reader-batchprint.conf
        DESTINATION ${CMAKE_INSTALL_DATADIR}/applications/context-menus)
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread CMakeLists.txt
Comment on lines 264 to 271
if (USE_PDFIUM_BUNDLE)
add_subdirectory(3rdparty/deepin-pdfium)
add_subdirectory(batch-print)

# Install context-menus (batch print)
install(FILES src/context-menus/deepin-reader-batchprint.conf
DESTINATION ${CMAKE_INSTALL_DATADIR}/applications/context-menus)
endif()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (broader_impact): The batch-print executable and its context-menu registration are only added when USE_PDFIUM_BUNDLE is enabled. Configurations that intentionally use the system PDFium library build the reader but omit the advertised batch-print feature entirely.

Triggers: When the project is configured with -DUSE_PDFIUM_BUNDLE=OFF.

Suggested fix: Move the batch-print subdirectory and context-menu installation outside the USE_PDFIUM_BUNDLE conditional; retain only the PDFium target selection inside the conditional.

Suggested change
if (USE_PDFIUM_BUNDLE)
add_subdirectory(3rdparty/deepin-pdfium)
add_subdirectory(batch-print)
# Install context-menus (batch print)
install(FILES src/context-menus/deepin-reader-batchprint.conf
DESTINATION ${CMAKE_INSTALL_DATADIR}/applications/context-menus)
endif()
if (USE_PDFIUM_BUNDLE)
add_subdirectory(3rdparty/deepin-pdfium)
endif()
add_subdirectory(batch-print)
# Install context-menus (batch print)
install(FILES src/context-menus/deepin-reader-batchprint.conf
DESTINATION ${CMAKE_INSTALL_DATADIR}/applications/context-menus)

@pengfeixx

Copy link
Copy Markdown
Contributor Author

关闭此 PR,改为从用户 fork 仓库发起 PR(Stage 6 返工:切换为 fork → linuxdeepin PR 模式)。

@pengfeixx pengfeixx closed this Sep 15, 2026
@pengfeixx
pengfeixx deleted the feat/batch-print branch September 15, 2026 03:41
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: pengfeixx

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants