espresso3389 / pdfrx

pdfrx is yet another PDF viewer implementation that built on the top of pdfium. The plugin currently supports Android, iOS, Windows, macOS, Linux, and Web.
MIT License
60 stars 36 forks source link

Drawing on pdf #106

Closed Cersin closed 1 month ago

Cersin commented 2 months ago

Hi, its drawing on pdf file possible? I need something like selecting text to make a bookmark but I need to select an area, maybe some rectangle to mark some area of the pdf.

Maybe there is a way to achieve that?

espresso3389 commented 2 months ago

There are two ways to do that:

The second one is not needed if you can do your jobs using widgets only. But if you want to place many widgets on a page, it may degrade the page rendering speed and you may want to switch to the second one.

espresso3389 commented 2 months ago

For the first one, there's no solid sample now but its parent is Stack and you can place Align or Positioned to place child widgets.

There's a sample for the second one that shows marker highlight. You should firstly check the pdfrx's example code.

Cersin commented 2 months ago

There are two ways to do that:

The second one is not needed if you can do your jobs using widgets only. But if you want to place many widgets on a page, it may degrade the page rendering speed and you may want to switch to the second one.

but how do i place a rectangle and get good coordinates from pdf to draw on it? i will appreciate any help, you are good guy :)

Cersin commented 2 months ago

@espresso3389 oooh i got it, thanks!

Cersin commented 2 months ago

@espresso3389 can you give me a hint how to get good pdf coordinates from overlay widget and draw it into pdf?

jaween commented 1 month ago

@Cersin

Here's what I have. The pageOverlaysBuilder has a page parameter with a width and height measured in physical points (1/72 of an inch). It also has a pageRect which represents the page's bounds relative to the PdfViewer in logical pixels. This is all we need to convert between points and pixels.

To convert a pixel to a point horizontally, you could use:

final pixelToPointX = page.width / pageRect.width;
final myPixel = 200.0; // From a gesture detector perhaps
final myPoint = myPixel * pixelToPointX;

Vertical is the same process. To convert a point to a pixel just divide by pixelToPoint.