pdfjs icon indicating copy to clipboard operation
pdfjs copied to clipboard

Text rotation / transform

Open bergur opened this issue 5 years ago • 1 comments

Hi Markus and thanks for this library.

I would love a text or cell option to rotate text in a cell to a certain angle. Often when creating PDF reports, there is limited space and headers take up alot of space when the column only has a number. Making a rotate property would be of a great help.

I would be happy to assist and make a pull request if you could point me in the right direction.

bergur avatar May 14 '19 21:05 bergur

Hi Bergur,

sorry for getting back so late. This definitely sounds like a reasonable feature to have! Unfortunately really hard to achieve with the approach I've chosen for pdfjs. pdfjs basically uses a greedy-algorithm (making decisions based on what is best at each step without looking far into the future, or even testing and comparing different variations) to decide where to place words (and when to do line breaks, etc.).

This works well for horizontal text, but makes rotated/transformed text a lot harder. As a first step, it would be useful to come up with an approach of how to calculate where each word goes in a rotated/transformed scenario, before I'd be able to point out some starting points in the code.

I guess the problem is defined by something like:

  • We have a cell with a given width (height is variable)
  • We have a set of words (that makes out the text content of the cell)
  • We have a function to measure the height and width of each word (and its style)
  • How to evenly distribute the words in the cell?

rkusa avatar May 29 '19 06:05 rkusa