talesluna / rust-printers

A rust library to printing APIs implementation for unix (cups) and windows (winspool).
https://crates.io/crates/printers
MIT License
63 stars 30 forks source link

Printing PDFs has a cross-platform solution: Ghostscript #33

Open lchjczw opened 1 month ago

lchjczw commented 1 month ago

There is a cross-platform solution for printing PDF files: Ghostscript.

Here are three implementation options:

Option 1: Cross-platform via Ghostscript's WASM implementation: Ghostscript WASM The advantage is ease of integration.

Option 2: Cross-platform via Ghostscript API binding: https://github.com/albel727/rust-ghostscript

Option 3: Cross-platform via Ghostscript's binary file, using the command line: gs -dBATCH -dNOPAUSE -sDEVICE=pswrite -sOutputFile=%printer%printer_name input.pdf

Two approaches:

Convert the PDF to a PS file, and then send the PS file to the printer (Option 1, Option 2, and Option 3 can all be used). Send the PDF directly to the printer using Ghostscript (Option 1 might require WASI, but Option 2 and Option 3 can both do this).

Overall, Option 2 is the best.

打印PDF文件的跨平台方案有ghostscript。

这里有两个实现方案:

方案1:通过ghostscript的wasm实现跨平台: ghostscript wasm 优点是接入比较方便

方案2:通过ghostscript的api bind实现跨平台: https://github.com/albel727/rust-ghostscript

方案3:通过ghostscript的二进制文件,通过命令行: gs -dBATCH -dNOPAUSE -sDEVICE=pswrite -sOutputFile=%printer%printer_name input.pdf

两种思路: 1.将PDF转为ps文件,然后将ps文件发送给打印机 (方案1和方案2,方案3都可以) 2.直接ghostscript将PDF发送到打印机(方案1可能需要wasi,方案2和方案3都可以)

综合来看,方案2是最好的

lchjczw commented 1 month ago

Ghostscript supports static compilation.

lchjczw commented 1 month ago

CUPS printing PDF files relies on Ghostscript.

jonahgeorge commented 1 month ago

I believe this would require re-licensing the project as AGPL?

https://www.ghostscript.com/licensing/

lchjczw commented 1 month ago

Rust Bind can use dynamic linking or

or use dynamic linking ,Only as an optional dependency, in compliance. rust-printers does not enforce binding to Ghostscript, and the user assumes responsibility for AGPL obligations.

Clearly distinguish license responsibilities to ensure that users comply with AGPL requirements during integration.