text position in editor
- Is there any way to know the precise coordinates of a piece of text on the
page when it occupies several lines?
I made a Print Preview for text entered into the editor, where I can set
margins, page orientation and a few other things. I cannot print that
preview as-is since it will have whatever margins, headers, footers and so
on the navigator has configured, not the ones I meant it to have.
So, I used fpdf (www.fpdf.org) on the server to create a PDF file but, the
layout does not match exactly the HTML preview.
From the HTML side, I don't know how to tell when a line breaks within a
paragraph so I do it on the server which is easy enough but, due to
differences in precise font size, character spacing, a few times things
don't come exactly the same. My choice on the server side on where to break
a paragraph might not exactly match the criteria of the browser.
So, I would like to know if there is any way that I can find out in the
browser where a line was broken.
Otherwise, I though I could make separate <span>s for each individual word
and then join again all those that share the same top value. I already do
that with mixed nodes, where there is text and something else, such as:
"all these go into a <b>single</b> line"
which I transform to
"<span>all these go into a </span><b>single</b><span> line</span>"
since for fpdf a line of text has to go all in the same font, the boldface
makes them three separate pieces of text. Enclosing it with a <span> allows
me to get the location of each block of text individually. I wonder if I
would have to do the same for each word. It can make the DOM tree quite
heavy and I was looking for something easier on memory.