flutter_pdf_render
flutter_pdf_render copied to clipboard
await page.render() crashed on web
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
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);
`
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?
Error is occured in Web platform. certificate (8).pdf
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.
@vishwajit76 Recent updates contains several null-safety changes. Could you please check the latest version?
I'm also getting this, on Flutter Web. Using plugin version 1.3.0.
From what I see there are two problems:
- 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 sayIf [width], [height], [fullWidth], [fullHeight], and [dpi] are all 0, the page is rendered at 72 dpi. - 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 inobjare 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);
Could you try 1.3.1?
Thanks for quick response. I tested 1.3.1
- Still getting
Exception: Invalid PDF page rendering rectangle (null x null)when calling render() with no args. - Still getting
Expected a value of type 'int', but got one of type 'Null', but now I see the only null value is pageNumber.
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
1.3.4 that fixes the issue is just released.