Painting a rectangle on top of PDFView (PDFView coordinate systems)

Q: I am drawing a rectangle on top of your PdfView class, which works
fine. I store the page number, the start, and end point in screen
coordinates.

What is the recommended way to get the rectangle to position properly
after PdfView is scrolled? Do I use your transformation matrix
somehow, do I translate the screen coordinates into page coordinates
then back into screen coordinates, or do I use the scroll values from
PdfView to adjust the rectangle on the screen?

I looked at your sample code for the PdfView and see that you multiply
a matrix, but that changed my rectangle (even though it did scroll the
flipped and stretched rectangle, and I see where you translate screen
coordinates to page coordinates, but that isn't what I'm trying to do.

What do you do in my case?
------
A: Instead of storing points in screen coordinates, you can convert
them to page (or canvas) coordinate system. The advantage of PDF page
(or canvas) coordinate system is that it is device independent. So if
the page is scrolled, rotated, zoomed, etc your data will display
exactly where it should. To paint the geometry and custom markup (in
your OnPaint method) you would need to convert back from page (or
canvas) coordinate system to screen coordinates. All of this is
illustrated in PDFView C# or VB sample project (http://www.pdftron.com/
net/samplecode.html#PDFView - you may want to look at code that draw a
rectangle for custom link creation tool or custom markup tool).

The main difference between page and canvas coordinate systems is that
canvas surrounds all pages within a PDFView page layout (you can look
at it as a single page that encircles all pages in the document
layout). As a result the conversion functions that work with canvas do
not need a page number to convert to and from screen coordinates.
Similar to PDF page coordinate system this coordinate system is device
independent and is using points as units. In PDFView class there are
utility methods (pdfview.Conv...) that can be used to convert points
back and forth between canvas, screen, and page coordinates.

Q: I have the rectangle on top of PdfView drawing and scrolling fine
thanks to your help, but just for your information, storing the
rectangle in canvas coordinates shifts around on the page through
different page zoom values.
Storing the coordinates in Page mode coordinates works correctly
through different page zoom values. I’m storing the rectangle values
in page coordinates and everything works great.

I am now trying to use your SelectByRect function. It does not have a
page number for an input, so it can’t be using page coordinates. It
doesn’t seem to be using the canvas coordinates (seems like the same
origion but different Y scaling). The documentation states that it
uses PDF coordinates. I can’t find this function in any of your
example code files.


A: I figured out the coordinates used by your SelectByRect function.
The coordinates are screen coordinates, not PDF coordinates as stated
in the API Ref. That’s why there is no page number required.