REG:

164 views
Skip to first unread message

Mohan Selvaraj

unread,
Feb 10, 2021, 7:53:43 AM2/10/21
to pdfium
Hi,

Is there any API to find the rotation of the individual characters in a PDF page? How to find the angle of the  individual characters in the document using PDFium?

            IntPtr textPage = PdfiumViewer.FPDFText_LoadPage(pages); // retrieved the texpage

int charCount = PdfiumViewer.FPDFText_CountChars(textPage);
            byte[] characters = new byte[(charCount + 1) * 2];
            PdfiumViewer.FPDFText_GetText(textPage, 0, charCount + 1, characters);
            string extractedText = string.Empty;
            for (int j = 0; j < charCount; j++)
            {
                uint unicodeCharacter = PdfiumViewer.FPDFText_GetUnicode(textPage, j);
                extractedText += ((char)unicodeCharacter).ToString(); // Need to get the rotation angle for the individual text
            }
Regards,
Mohan S 

Olivia Yingst

unread,
Feb 10, 2021, 1:09:17 PM2/10/21
to Mohan Selvaraj, pdfium
Hi Mohan, 

Maybe you can try to use the API FPDFText_GetMatrix(). This should return the transformation matrix for a particular character. Then you can calculate the rotation angle from the matrix.

Regards,
Olivia

--
You received this message because you are subscribed to the Google Groups "pdfium" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pdfium+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pdfium/7d4a1208-0a7c-4d59-b383-971a83e1ac83n%40googlegroups.com.


--

Olivia(Hui) Yingst | Software Engineer | huiy...@google.com | 213-399-8487

Desika R

unread,
Sep 20, 2021, 9:57:46 AM9/20/21
to pdfium
Hi Team,

Thanks for your update,

We have tried this below code to get the rotation angle for the individual text. But it returns Zero for the rotated text. Kindly suggest us to retrieve the rotation of the character.

            double m1, m2, m3, m4, m5, m6;
            PdfiumViewer.FPDFText_GetMatrix(textObjects[index], out m1, out m2, out m3, out m4, out m5, out m6);
            double radians = Math.Atan2(m3, m1);
            int textRotation = (int)(radians * 180 / Math.PI);
            return textRotation;

Regards,
Desika
 

Lei Zhang

unread,
Sep 20, 2021, 2:48:13 PM9/20/21
to Desika R, pdfium
Please provide a sample PDF that demonstrates the issue. The code
looks ok for calculating the rotation of the text only, but there may
be other transformation matrices in effect. A sample PDF will help
determine why your code returns 0.
> To view this discussion on the web visit https://groups.google.com/d/msgid/pdfium/b47bfefd-8bc3-47f5-9a44-99cd94895b9cn%40googlegroups.com.

Desika R

unread,
Sep 22, 2021, 4:24:39 AM9/22/21
to pdfium
Hi Team,

Please find the sample PDF to replicate the issue.

Regards,
Desika
test-rotated.pdf

Lei Zhang

unread,
Sep 22, 2021, 8:28:29 PM9/22/21
to Desika R, pdfium
In this sample PDF, the rotation comes from page rotation, not
character rotation. Looking at object 1 0, the page object for the 1st
page, The /CropBox and /MediaBox are both [0 0 595 842]. This looks
like a portrait page, except the page object also has /Rotation 270.
Thus PDF Viewers display the page in landscape mode. Use
FPDFPage_GetRotation() to get the page rotation.
> To view this discussion on the web visit https://groups.google.com/d/msgid/pdfium/9710a659-8d8c-4d64-8405-564e36a827c1n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages