flutter-pi icon indicating copy to clipboard operation
flutter-pi copied to clipboard

Support for viewing PDF's

Open RadJKW opened this issue 2 years ago • 7 comments

My application requires video playback and pdf viewing on a raspberry pi.

I switched to flutter-pi with the news that gstreamer is being used. My testing showed that using flutter-pi and gstreamer (video_player) works much better than dart_vlc.

However, now I can no longer view my pdf documents using https://pub.dev/packages/printing. The package relies on pdfium to be compiled for the platform. My current implementation results in this error Error getting printing info: MissingPluginException(No implementation found for method printingInfo on channel net.nfet.printing).

I've tried a few other pdf packages designed for android but no luck so far. Is there any solution available?

RadJKW avatar Apr 13 '22 21:04 RadJKW

@ardera Could you elaborate on this?

RadJKW avatar Apr 27 '22 20:04 RadJKW

"viewing"?

As said on #250:

"flutter-pi can only run without desktop. Desktop support is not planned and won't be implemented. You can try using arm64 and the official linux desktop embedder, or sony's flutter-elinux, or toyotas embedder."

This repository is all about removing desktop/viewing need, which "without X" means, if you need more than CLI don't use.

top-master avatar Sep 17 '22 06:09 top-master

@top-master not sure I agree, flutter is a GUI framework so of course you can talk about viewing PDFs inside flutter. Opening a PDF viewer to view the pdf would not make sense however, but I'm not sure that's what the printing plugin does.

That printing plugin could work in flutter-pi if the native code would be ported to flutter-pi. It supports offscreen rendering of PDFs to a bitmap (See here), the bitmap you can either import into a GL texture or dart:ui Image and present it.

ardera avatar Sep 19 '22 12:09 ardera

@RadJKW I am currently working on an implementation for this using ImageMagick's MagickWand C API. You can observe the progress on my fork (branch feature/printing).

bojidartonchev avatar Sep 19 '23 20:09 bojidartonchev

@bojidartonchev, do I understand well, that with your fork it will be possible to display PDF file on the screen?

eximius313 avatar Sep 24 '23 20:09 eximius313

Hi @eximius313,

I am using the pdf plugin to generate a pdf, then rasterize it and send it to thermal printer for printing. My implementation is rasterizing it as a bitmap, so you will need to decode it on flutter side.

await for (var page in Printing.raster(await doc.save())) {
  final image = i.decodeImage(page.pixels)!;

  bytes += generator.image(image);
}

The esc_pos_utils I am using for printing is a bit outdated and didn't work with the new image plugin and I didn't have time for investigating it, so I proceed using image_v3 instead. But if you need it only for rendering, image should do the job.

bojidartonchev avatar Sep 25 '23 08:09 bojidartonchev

thanks @bojidartonchev!

eximius313 avatar Sep 25 '23 09:09 eximius313