pdf-lib
pdf-lib copied to clipboard
Can you provide a function to write text within a rectangle?
Describe your idea
Can you provide a function to write text within a rectangle? I have a scenario where the content I need to write may be much wider than the page width. So I hope that when writing, it can automatically wrap text. I can give it a higher height. Currently, I manually wrap text by calculating, but it is a little troublesome. I would like to confirm if you plan to add a similar function. Thank you again for your efforts!
How could this be implemented?
Based on the given rectangular width, calculate whether the currently clipped content plus one more character will exceed this width. If so, write the currently clipped content and adjust the y value for the next clipped writing.
What problem are you trying to solve?
write text within a rectangle or with multible lines
Why does this matter to you?
What I want to write is always paragraph by paragraph
Would others find this helpful?
It depends
Are you interested in implementing your proposal?
Yes
Why are you submitting a proposal?
It's not a good idea to check if that's a good idea
Additional Notes
No response
In theory this is only done in PDF with "Free Text" as they are "Flowables" so it is easy in many PDF readers, however the text is normally simple Latin (not usually UTF or styled until it is flattened into single lines) PDF body has no concept of paragraphs all lines are equal width between Right and Left edges of crop boundary, hhence when you write to media beyond crop width the text simply is invisible but not wrapped (there is no concept of line wrapping in PDF) I gave an example here https://stackoverflow.com/a/76675218/10802527