Am 20.03.2020 um 11:06 schrieb PDF Developer:
Hello,
I am experimenting with extracting text from a PDF. Part of the customer
requirements is to extract text in a certain colour. I adapted the
PrintTextColour Sample. Since there is a need to process text that could be at
0..45..90..135.. etc However the TextPosition.getDir() didn't appear to give me
the correct angle sometimes - am I missing something? In the end I calculated
the angle from the TextPosition.getTextMatrix() which is where I understood
getDir() derived the information.
Can someone enlighten me - is this a mistake on my part or a "hiccup" in PDFBox?
PDFDev
You need to use getTextMatrix(), see its javadoc, and also the javadoc
of getDir() that shows why it is not what you need. See also the source
code of ExtractText.java, the "rotationMagic" option, and this source
code segment:
static int getAngle(TextPosition text)
{
// should this become a part of TextPosition?
Matrix m = text.getTextMatrix().clone();
m.concatenate(text.getFont().getFontMatrix());
return (int)
Math.round(Math.toDegrees(Math.atan2(m.getShearY(), m.getScaleY())));
}
Tilman
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: users-h...@pdfbox.apache.org