Hopding / pdf-lib

Create and modify PDF documents in any JavaScript environment
https://pdf-lib.js.org
MIT License
6.89k stars 656 forks source link

Document what the unit is for page dimensions #1531

Open faltenberg opened 12 months ago

faltenberg commented 12 months ago

Describe your idea

In src/api/sizes.ts the A4 page format is defined with the dimension of 595.28 x 841.89. But what are the units? It is definitely not millimeters, nor is that in inches. When using addPage() we can specify the page dimensions as well. But in which units is that expressed?

Proposal to at least add that information to the documentation or support human-understandable standard units like millimeters or inches, similar to what jspdf-lib does.

How could this be implemented?

The documentation would need to be improved with the deeper insights.

What problem are you trying to solve?

I try to better understand where items end up on the PDF page so I can easily add some exact margin for page headers, page content and page footers.

Why does this matter to you?

When working with normal A4 paper I know the sizes and can easily setup things like 2cm margins. With the units in this library that are not documented nor intuitive I struggle to understand the relationship of the underlying units to the paper size.

Would others find this helpful?

I strongly believe that an improved documentation would help others just the same. It is a fundamental information.

Are you interested in implementing your proposal?

Yes

Why are you submitting a proposal?

I would like if the people with deep insight into this library could provide a documentation. A change of page sizes to standard units would be desired, however, I understand that there are more important issues to fix and features to implement.

Additional Notes

No response

ctison commented 11 months ago

As stated in this page:

Space in a PDF file, also known as user space, is measured in PDF units. The PDF specification defines PDF units as 72 PDF units to 1 inch.

And 1 inch is equal to 2.54 centimeters.

lookus69 commented 2 months ago

As stated in this page:

Space in a PDF file, also known as user space, is measured in PDF units. The PDF specification defines PDF units as 72 PDF units to 1 inch.

And 1 inch is equal to 2.54 centimeters.

Thanks for the info! wouldnt it be great to find that on the official docs? i dont know how to upvote this issue, but would be pretty useful!