flutter_pdf_render icon indicating copy to clipboard operation
flutter_pdf_render copied to clipboard

Image is 180 rotated and horizontally inversed

Open paqio opened this issue 3 years ago • 16 comments
trafficstars

final document = await PdfDocument.openData(await file.readAsBytes()); for (var i = 0; i < document.pageCount; i++) { final page = await document.getPage(i + 1); // Starts from 1 var imgPDF = await page.render( width: page.width.toInt(), height: page.height.toInt()); ui.Image img = await imgPDF.createImageIfNotAvailable();

the image ends up being invested, even tho pdf is normal.

paqio avatar Feb 23 '22 00:02 paqio

What platform are you using? And could you please give me the sample PDF file if possible.

espresso3389 avatar Feb 23 '22 01:02 espresso3389

It's web. test (1)

paqio avatar Feb 23 '22 09:02 paqio

I think this is the issue: https://github.com/mozilla/pdf.js/issues/10400

paqio avatar Feb 23 '22 17:02 paqio

@paqio

The things are too much complicated... You can see the example code renders the image correctly with your PDF file if you're on Flutter stable (**related issue):

image

The current render method on Web platform has been mis-implemented and thus the GUI side internal code flips the image upside-down on the rendering process to correct it. It means that the behavior is not-correct but regareded as designed and expected.

The critical issue here is that the Web behavior is different from the ones of other platforms. So I should fix the problem though it breaks the backward compatibility...

espresso3389 avatar Feb 23 '22 18:02 espresso3389

Flutter 2.8.1 • channel stable • https://github.com/flutter/flutter.git Framework • revision 77d935af4d (10 weeks ago) • 2021-12-16 08:37:33 -0800 Engine • revision 890a5fca2e Tools • Dart 2.15.1

So you are saying that in your example it flipps? or? Is there a quick fix for me at the moment?

Because i am using the workaround already window.workaround_for_flutter_93615 = true;

paqio avatar Feb 23 '22 18:02 paqio

I updated to the latest stable 2.10.2, issue remains

paqio avatar Feb 23 '22 19:02 paqio

@paqio For what purpose do you use the raw RGBA image? If it is simply passed to Flutter widget, you can flip the image on GUI side; otherwise PdfPageImage.buffer contains the raw RGBA data and you can easily flip the data on your hand.

Anyway, I'll fix the issue next week...

espresso3389 avatar Feb 23 '22 19:02 espresso3389

i need an ui.Image to merge them into one. Ended up using pdfx for now, maybe you can check their way of handling the render

paqio avatar Feb 23 '22 19:02 paqio

@paqio

i need an ui.Image to merge them into one. Ended up using pdfx for now, maybe you can check their way of handling the render

Do you want to conbine page images into one to form a large one? Or generate multipage?

espresso3389 avatar Feb 23 '22 23:02 espresso3389

Any updates on this?

Felixduelmer avatar Apr 07 '22 07:04 Felixduelmer

Any update will be appreciated.

MSSPL-KamalenduGarai avatar Jul 12 '22 10:07 MSSPL-KamalenduGarai

At least for me this seems to be fixed now in version 1.3.0. Thanks @espresso3389

IVLIVS-III avatar Aug 08 '22 21:08 IVLIVS-III

I'm getting this in flutter web, plugin version 1.3.1. Doesn't happen on android.

syonip avatar Aug 09 '22 16:08 syonip

Does anyone have some Flutter web example that easily reproduces the issue?

espresso3389 avatar Aug 14 '22 15:08 espresso3389

can you use transform in widget

Container( padding: const EdgeInsets.all(10.0), color: Colors.grey, child: Center( child: **Transform( alignment: Alignment.center, transform: Matrix4.identity()..scale(1, -1),** child: Image.memory(_pageImage.buffer.asUint8List(), fit: BoxFit.contain))))

Bramiproject avatar Jan 30 '24 16:01 Bramiproject