flutter_pdf_render icon indicating copy to clipboard operation
flutter_pdf_render copied to clipboard

await page.render() crashed on web

Open vishwajit76 opened this issue 3 years ago • 8 comments

pdf is successfully opened but when i try to render page, web app is crashed.

Error: Expected a value of type 'int', but got one of type 'Null' at Object.throw_ [as throw] (http://localhost:49752/dart_sdk.js:5063:11) at Object.castError (http://localhost:49752/dart_sdk.js:5022:15) at Object.cast [as as] (http://localhost:49752/dart_sdk.js:5347:17) at Function.as (http://localhost:49752/dart_sdk.js:19820:19) at _render (http://localhost:49752/packages/pdf_render/src/pdf_render_method_channel.dart.lib.js:602:97) at _render.next (<anonymous>) at http://localhost:49752/dart_sdk.js:40537:33 at _RootZone.runUnary (http://localhost:49752/dart_sdk.js:40407:59) at _FutureListener.thenAwait.handleValue (http://localhost:49752/dart_sdk.js:35328:29) at handleValueCallback (http://localhost:49752/dart_sdk.js:35896:49) at Function._propagateToListeners (http://localhost:49752/dart_sdk.js:35934:17) at _Future.new.[_completeWithValue] (http://localhost:49752/dart_sdk.js:35782:23) at async._AsyncCallbackEntry.new.callback (http://localhost:49752/dart_sdk.js:35803:35) at Object._microtaskLoop (http://localhost:49752/dart_sdk.js:40675:13) at _startMicrotaskLoop (http://localhost:49752/dart_sdk.js:40681:13) at http://localhost:49752/dart_sdk.js:36156:9

vishwajit76 avatar Dec 23 '21 05:12 vishwajit76

crashed on pageNumber `

    return PdfPageImageMethodChannel._(
    pageNumber: obj['pageNumber'] as int,
    x: obj['x'] as int,
    y: obj['y'] as int,
    width: retWidth,
    height: retHeight,
    fullWidth: obj['fullWidth'] as double,
    fullHeight: obj['fullHeight'] as double,
    pageWidth: obj['pageWidth'] as double,
    pageHeight: obj['pageHeight'] as double,
    pixels: pixels,
    buffer: ptr);

`

vishwajit76 avatar Dec 23 '21 05:12 vishwajit76

Basically, such error causes on PDF open failure. On which platform did you get the error? And, if possible, could you give me the PDF file?

espresso3389 avatar Dec 23 '21 06:12 espresso3389

Error is occured in Web platform. certificate (8).pdf

vishwajit76 avatar Dec 23 '21 10:12 vishwajit76

I could not reproduce the issue on 1.0.18. Anyway, getPage may throw exception on PDF decoder error. And your code should handle exception correctly.

espresso3389 avatar Dec 30 '21 17:12 espresso3389

@vishwajit76 Recent updates contains several null-safety changes. Could you please check the latest version?

espresso3389 avatar Jan 19 '22 17:01 espresso3389

I'm also getting this, on Flutter Web. Using plugin version 1.3.0.

From what I see there are two problems:

  1. If calling page.render() with no params, I get PlatformException(error, Exception: Invalid PDF page rendering rectangle (null x null), null, null) although the docs say If [width], [height], [fullWidth], [fullHeight], and [dpi] are all 0, the page is rendered at 72 dpi.
  2. If I do send some values to width, height, fullWidth, fullHeight, I get Expected a value of type 'int', but got one of type 'Null' It seems the reason is indeed this code: https://github.com/espresso3389/flutter_pdf_render/blob/85def54ac2278d6398dd915103e4f01f31f88e8e/lib/src/pdf_render_method_channel.dart#L263 All the values in obj are null. I changed the code to this and it works, but I'm not sure about some of the values:
return PdfPageImageMethodChannel._(
        pageNumber: pageNumber as int,
        x: x as int,
        y: y as int,
        width: retWidth as int,
        height: retHeight as int,
        fullWidth: fullWidth as double,
        fullHeight: fullHeight as double,
        pageWidth: fullWidth as double,
        pageHeight: fullHeight as double,
        pixels: pixels,
        buffer: ptr);

syonip avatar Aug 09 '22 13:08 syonip

Could you try 1.3.1?

espresso3389 avatar Aug 09 '22 14:08 espresso3389

Thanks for quick response. I tested 1.3.1

  1. Still getting Exception: Invalid PDF page rendering rectangle (null x null) when calling render() with no args.
  2. Still getting Expected a value of type 'int', but got one of type 'Null' , but now I see the only null value is pageNumber.

syonip avatar Aug 09 '22 16:08 syonip

Also encountering the problem in 1.3.1 on web (Chrome): Uncaught (in promise) Error: PlatformException(error, Exception: Invalid PDF page rendering rectangle (null x null), null, null)

pdfDocument = await PdfDocument.openData(bytes); passes. page = await pdfDocument.getPage(pageNumber); passes. img = await page.render(); fails.

Using: pdfjs 2.4.456

guidotheelen avatar Sep 15 '22 10:09 guidotheelen

1.3.4 that fixes the issue is just released.

espresso3389 avatar Sep 26 '22 03:09 espresso3389