Question about Quads

Hello,

I have some questions about the quads.

1.) PdfViewWPF.Selection.GetQuads() is independent of how the page is rotated? Is that true and if so, are the points always oriented from the upper left corner (in terms of coordinates)?
2.) These points can be converted to screen coordinates with PdfViewWPF.ConvPagePtToScreenPt(). Does this method depend on how the page is rotated? If so, do the points have to be adjusted first with the page matrix (pdftron.PDF.Page.GetDefaultMatrix())?

using (var selection = _viewer.GetSelection(1))
            {
                if (selection != null)
                {
                    var quads = selection.GetQuads();

                    int sz = quads.Length / 8;

                    int k = 0;

                    for (int i = 0; i < sz; ++i, k += 8)
                    {
                        var p1 = new System.Windows.Point(quads[k], quads[k + 1]);
                        var p2 = new System.Windows.Point(quads[k + 2], quads[k + 3]);
                        var p3 = new System.Windows.Point(quads[k + 4], quads[k + 5]);
                        var p4 = new System.Windows.Point(quads[k + 6], quads[k + 7]);
                    }
                }
            }

You asked: 1.) PdfViewWPF.Selection.GetQuads() is independent of how the page is rotated? Is that true and if so, are the points always oriented from the upper left corner (in terms of coordinates)?

The points are independent of how the page is rotated in the viewer. They are however in page coordinates. If the page rotation is set to e_0 the origin is at the bottom left corner. If the page has its rotation set to a value other than e_0 then the origin will change.

You asked: 2.) These points can be converted to screen coordinates with PdfViewWPF.ConvPagePtToScreenPt(). Does this method depend on how the page is rotated?

The output of PdfViewWPF.ConvPagePtToScreenPt() takes page rotation into account.

You asked: If so, do the points have to be adjusted first with the page matrix (pdftron.PDF.Page.GetDefaultMatrix())?

No you don’t need to do that as PdfViewWPF.ConvPagePtToScreenPt() takes page rotation into account.

Can you please elaborate more on your use case? as to what you are trying to achieve with the Quads.

Thanks,
Yasser
PDFTron Systems Inc.

Hello, Yasser,

I use the quads to describe the exact position of a selection. Using the conversion method, I convert them to screen coordinates and then use them for overlays that I draw over the selection. This also works well. Using this system (4 points instead of a rectangle of 2 points) works better when selecting rotated text on the page. What the TextExtractor doesn’t seem to support yet is the specification of where to extract the text from. I can specify a rect, but with rotated text it seems to me that something is inaccurate or it can come to overlaps with the line above or below it, which is also rotated.

Greeting

Daniel
Am Samstag, 22. Juni 2019 01:22:04 UTC+2 schrieb Yasser Khan:

You asked: 1.) PdfViewWPF.Selection.GetQuads() is independent of how the page is rotated? Is that true and if so, are the points always oriented from the upper left corner (in terms of coordinates)?

The points are independent of how the page is rotated. They are however in page coordinates. The points are oriented from the bottom left corner of the page.

You asked: 2.) These points can be converted to screen coordinates with PdfViewWPF.ConvPagePtToScreenPt(). Does this method depend on how the page is rotated?

The output of PdfViewWPF.ConvPagePtToScreenPt() takes page rotation into account.

You asked: If so, do the points have to be adjusted first with the page matrix (pdftron.PDF.Page.GetDefaultMatrix())?

No you don’t need to do that as PdfViewWPF.ConvPagePtToScreenPt() takes page rotation into account.

Can you please elaborate more on your use case? as to what you are trying to achieve with the Quads.

Thanks,
Yasser
PDFTron Systems Inc.

Hello Daniel,

Thank you for your reply. We rarely come across PDF files where text is not horizontally or vertically aligned. It would be great if you can provide us files where you encountered this issue for us to test.

Best,
Yasser