fschutt / printpdf

A fully-featured PDF library for Rust, WASM-ready
https://fschutt.github.io/printpdf/
MIT License
829 stars 98 forks source link

In `0.7` this isn't possible (it will always embed the entire font), in `0.8` the default behaviour is to subset the font on save. In other words, just wait until `0.8` is released. #196

Closed bianbiandashen closed 1 week ago

bianbiandashen commented 1 week ago
          In `0.7` this isn't possible (it will always embed the entire font), in `0.8` the default behaviour is to subset the font on save. In other words, just wait until `0.8` is released.

Originally posted by @fschutt in https://github.com/fschutt/printpdf/issues/189#issuecomment-2452938099

0.8 Can I use it now? In addition, does the function of subset font also support windows?

bianbiandashen commented 1 week ago

Can you show your code and I can also work with you to build subsets? In addition, even if 0.8 activates this ability When adding_external_font, the cache capabilities should still need to be preserved, right?image

fschutt commented 1 week ago

You can use printpdf = { git = „https://github.com/fschutt/printpdf“ } in your Cargo.toml and look at the examples, they have been updated for the new version. Only minor bugs with SVGs and layers need to be worked out, the rest is the same API.

I am mainly working on the HTML renderer in 0.8, so it will still take some time to release (since 0.8 is the biggest refactoring in 5+ years, I don‘t want to rush it, I guess end of November it‘ll be stable enough).

fschutt commented 1 week ago

When adding_external_font, the cache capabilities should still need to be preserved, right?

In 0.8 it uses a unique FontId String instead of a Rust reference to identify where a font was used in the document:

let mut doc = PdfDocument::new(„title“);
let font = ParsedFont::from_bytes(BYTES).unwrap();
let fontid = doc.add_font(&font); // random string
fangqi5 commented 1 week ago

Hi, my usage scenario is to draw PDF and print on Windows system, including win7/win10/win11. Does this code support the above systems?

fangqi5 commented 1 week ago

When adding_external_font, the cache capabilities should still need to be preserved, right?

In 0.8 it uses a unique FontId String instead of a Rust reference to identify where a font was used in the document:

let mut doc = PdfDocument::new(„title“);
let font = ParsedFont::from_bytes(BYTES).unwrap();
let fontid = doc.add_font(&font); // random string

Hi When I configure to download the code from git, the following error appears when running locally. My rust version is rustc 1.79.0 (129f3b996 2024-06-10)

fschutt commented 1 week ago

Hi, my usage scenario is to draw PDF and print on Windows system, including win7/win10/win11. Does this code support the above systems?

Yes.

Hi When I configure to download the code from git, the following error appears when running locally. My rust version is rustc 1.79.0 (129f3b996 2024-06-10)

Please post the error.

fangqi5 commented 1 week ago

Hi, my usage scenario is to draw PDF and print on Windows system, including win7/win10/win11. Does this code support the above systems?

Yes.

Hi When I configure to download the code from git, the following error appears when running locally. My rust version is rustc 1.79.0 (129f3b996 2024-06-10)

Please post the error.

error: unexpected token: `<-`
  --> /Users/fangqiji/.cargo/git/checkouts/printpdf-ad3d01efe2a6c4c7/c03ca60/src/types/plugins/graphics/two_dimensional/line.rs:93:45
   |
93 |                     operations.place_back() <- Operation::new(OP_PATH_PAINT_FILL_STROKE_CLOSE_NZ, vec![]);
   |                                             ^^
   |
help: if you meant to write a comparison against a negative value, add a space in between `<` and `-`
   |
93 |                     operations.place_back() < - Operation::new(OP_PATH_PAINT_FILL_STROKE_CLOSE_NZ, vec![]);
   |                                             ~~~
fschutt commented 1 week ago

@fangqi5 You are for some reason using a version c03ca60, a printpdf version from July 2017. You don't need to download the code from git, just put this in your Cargo.toml:

printpdf = { git = "https://github.com/fschutt/printpdf", branch = "master" }

or:

printpdf = { git = "https://github.com/fschutt/printpdf", rev = "5109221b" } # todays commit

In 2017 the place_back() <- notation was allowed on nightly, that's why it doesn't compile anymore.

fschutt commented 1 week ago

@fangqi5 Next time, please don‘t blindly copy code (or in this case version numbers) from ChatGPT.

fangqi5 commented 1 week ago
rev

I sincerely apologize. While my Cargo.toml file configuration aligns with what you provided, the absence of the "cargo clean" step resulted in downloading code that did not meet expectations.

fangqi5 commented 4 days ago

Hi, I've come across issue #27 in the allsorts repository where subsetting fonts on Windows results in invalid font files. I'm wondering if there are any workarounds available for this issue?

fschutt commented 3 days ago

@fangqi5 I am debugging the layout at the moment, it also seems that the kerning / layouting is off when using subset fonts... not sure why.

bianbiandashen commented 2 days ago

There is a great need for version 0.8 of printpdf to support font pumping technology. You should also use allsorts as a rust-based solution, right? There have been complaints that pdf is too big and will cause too long printing time.