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
75 stars 41 forks source link

Is there a way to convert the Document to a Uint8List? #193

Closed xpwmaosldk closed 13 hours ago

xpwmaosldk commented 4 days ago

I'm on the web. I have loaded the document using PdfViewer.data. Is there a way to set up the overlays and get the document with the overlays included as byte data (Uint8List)?

espresso3389 commented 4 days ago

Do you want to manupulate PDF page image? If so, you'd better use PdfDocument.openData to load the document and then create page image.

final doc = PdfDocument.openData(...);
final pdfImage = await doc.pages[0].render();
// Get raw pixel data RGBA or BGRA depending on platform
final rawRgba = pdfImage.pixels;

You can access the raw RGBA data and then you can use any kind of Image processing library or Dart:ui to manipulate the image.

espresso3389 commented 4 days ago

NOTE: you should dispose pdfImage and doc there.

xpwmaosldk commented 16 hours ago

This is my code snuppet

PdfViewer.data(
  pdfBytes,
  ...,
  controller: controller,
  pageOverlaysBuilder:(...)=>[
    Text('pageOverlaysBuilder'),
    Image(...),
  ]
);

How can I obtain the data that includes the overlays? I would like to perform the following tasks:

Unit8List data = controller.getCurrentPdfData()
// make file from data

I think there should be something like controller.getCurrentPdfData() to get this.

espresso3389 commented 16 hours ago

What do you mean by "overlays"?

xpwmaosldk commented 15 hours ago

The components such as Text, Image, etc. are inside the pageOverlaysBuilder. I would like to retrieve the PDF data with these components that are drawn on the page.

espresso3389 commented 13 hours ago

Try https://pub.dev/packages/screenshot or such. pdfrx does not have such feature.

xpwmaosldk commented 13 hours ago

Thank you. I have already tried that, but I had to convert the images back into PDFs for each page, which was very costly and slow.

I'll have to look for another method.

espresso3389 commented 12 hours ago

Basically pdfrx's widgets are only to interact with user. If you want to handle PDF page images directly, use PdfDocument and so on. And, if you want to do overlay the things such as link or text, PdfPage has functions to extract them. And all you have to do is just draw them on the page image. It's not difficult but it takes some time to implement them. And, I don't want to do that because it's useless for pdfrx usage.