Butterfly icon indicating copy to clipboard operation
Butterfly copied to clipboard

[Feature request]: Advanced pdf features

Open CodeDoctorDE opened this issue 2 years ago • 15 comments

Is your feature request related to a problem? Please describe

PDFs are a big topic for importing and exporting. Featuring text support, ... would help people using the app in production

Describe your feature request!

Add this

Additional context

We need to create our own library for this. https://github.com/DavBfr/dart_pdf does not support importing pdfs in the free tier.

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

CodeDoctorDE avatar Jan 04 '23 17:01 CodeDoctorDE

This is a good package. And I have some advices for rendering pdf. There is a package pdfrx backed by pdfium that support some advanced pdf features. Specially, so far Butterfly only imports pdf to images as canvas background. Butterfly's Renderer use canvas to draw backgroud which it is not better for rendering pdf clearly. Maybe put canvas on pdfrx viewer widget ?https://github.com/espresso3389/pdfrx?tab=readme-ov-file#additional-customizations. It provides Per-page Customization using Widget and Per-page Customization using Canvas.

lbk861 avatar Mar 20 '25 07:03 lbk861

I'm usually against non-canvas renderers. My whole rendering system relies on the canvas and it allows saving performance when creating new elements by just saving the last rendering. A widget would mean building an extra widget tree to display these.

My other idea was a "dynamic image" builder. It doesn't convert it on import, instead it saves the PDF and depending on the zoom level, it renders the image

CodeDoctorDE avatar Mar 20 '25 07:03 CodeDoctorDE

I'm not sure meaning of "dynamic image" builder. Isn't this a pdf render? I think pdfium directly render as an image depending on the zoom level. And I guess that you want to render pdf only by canvas. But comparing with pdfium, pdfium is a mature library. I think rendering by canvas may be a loss of performance.

lbk861 avatar Mar 20 '25 08:03 lbk861

Yeah, a real pdf renderer that renders an image and paints it on the canvas. The image render part uses pdfium under the hood in the current version, so it doesn't make a difference . If we use widgets or canvas

CodeDoctorDE avatar Mar 20 '25 08:03 CodeDoctorDE

Oh, I see.

lbk861 avatar Mar 20 '25 09:03 lbk861

I just looked at it and pdfrx seems like to have a canvas system inside it that I can use. Putting it on my todo list

CodeDoctorDE avatar Jun 09 '25 08:06 CodeDoctorDE

Oh looks like it cannot create pdfs... need to look for a different solution

CodeDoctorDE avatar Jun 09 '25 08:06 CodeDoctorDE

Pdfrx use pdfium. You can create pdf by pdfium api directly. btw pdfrx may not bind all pdfium api with ffigen, you ffigen them.

lbk861 avatar Jun 09 '25 10:06 lbk861

Yeah that's my problem. Only loading functions of pdfium are binded. Also we need to use pdf.js on web.

I'm currently thinking about https://lib.rs/crates/printpdf. With flutter_rust_bridge it is easy to create bindings for dart and since it doesn't depend on native code, we can support all platforms.

CodeDoctorDE avatar Jun 09 '25 10:06 CodeDoctorDE

Cool, rust is good. But I think pdfium is a mature library which also supports wasm now.

lbk861 avatar Jun 09 '25 11:06 lbk861

Hmm, okay... I'm not a big c++ pro but maybe I can do some things with ffigen and pdfium to get my own bindings to pdfium...

CodeDoctorDE avatar Jun 09 '25 11:06 CodeDoctorDE

Found out ffigen doesn't really support web... Are you familiar in creating bindings in dart?

CodeDoctorDE avatar Jun 09 '25 11:06 CodeDoctorDE

https://github.com/ajrcarey/pdfium-render has rust bindings

lbk861 avatar Jun 09 '25 11:06 lbk861

No, I only know https://github.com/espresso3389/pdfrx/wiki/Enable-Pdfium-WASM-support

lbk861 avatar Jun 09 '25 11:06 lbk861

This looks wonderful, I will try it

CodeDoctorDE avatar Jun 09 '25 11:06 CodeDoctorDE

Okay looks like pdfrx gets editing/saving features some time in the future: https://github.com/espresso3389/pdfrx/issues/421.

For now i think i will keep the pdf package for now. For starting with advanced pdf features we need to do this:

  • Saving the real pdf file instead of rendering on import
  • If the pdf is visible, only render this part (with the specific resolution)

CodeDoctorDE avatar Aug 06 '25 09:08 CodeDoctorDE

Added in 2.4.0-beta.3. I think "advanced" pdf features like highlighting or more will come very far in the future since the pdf library we use currently only allows this in a premium plan

CodeDoctorDE avatar Aug 16 '25 20:08 CodeDoctorDE