fschutt / printpdf

An easy-to-use library for writing PDF in Rust
https://docs.rs/printpdf/
MIT License
777 stars 95 forks source link

Is it possible to align text to the top? #104

Closed YaxinCheng closed 2 years ago

YaxinCheng commented 2 years ago

Hi, I'm trying to generate a pdf from top to bottom, but the use_text accepts y as the distance to the bottom. What I am trying to achieve is to be able to export the pdf in different font sizes but all have the same top and bottom margin (5pt). However, given the current api, I can only set the bottom margin.

I want to have the ability to change fonts and font size, so it will be hard to calculate the distance to the bottom. Is there a way to do it yet? I was also looking into getting the height of a specific font size, but had no luck on that.

YaxinCheng commented 2 years ago

Seems like it has already been answered: https://github.com/fschutt/printpdf/issues/49. I will close this for now

fschutt commented 2 years ago

Yeah well you need to use an extra crate for font parsing. I've written azul-text-layout for that purpose, but it's a separate crate.

"y as distance to the bottom" is a PDF limitation, that's how PDF files store the information internally. Whatever you use, you have to calculate that distance somehow.

If you don't need ultra-high performance you could also look into wkhtmltopdf solutions