Hi,
I am trying to implement a "hello world" widget to display a PDF in a Flutter application.
My code is close to the one used in the example provided by Syncfusion, but unfortunately, I can't make it work, and I do not find any detailed error to help me find the issue.
At some point in the app, I have :
SfPdfViewer.network('https://cdn.syncfusion.com/content/PDFViewer/flutter-succinctly.pdf',
onDocumentLoadFailed: (c){print(c.description);},
The PDF loading fails, and the error message is : There was an error opening this document.
Any idea what I miss or how I can have more detail on the issue ?
Hi Vivien Cuisinier,
For the web platform, we have used PdfJs for rendering the PDF pages, so the script file must be referred to in your web/index.html file. On your web/index.html file, add the following script tags, somewhere in the head or body of the document:
|
<script src="//cdnjs.cloudflare.com/ajax/libs/pdf.js/2.4.456/pdf.min.js"></script> <script type="text/javascript"> pdfjsLib.GlobalWorkerOptions.workerSrc = "//cdnjs.cloudflare.com/ajax/libs/pdf.js/2.4.456/pdf.worker.min.js"; </script> |
To know more about information about getting started with Flutter Web, kindly refer the following documentation link.
Regards,
Deepika Ravi
Dear Deepika,
Thank you for your quick answer. I have tried this and started the application on Google Chrome: it works!
Unfortunately, I am working on a Windows application, and adding this script doesn't solve the issue as it is specific to the Web Platform.
Do you have the same kind of answer for Windows Flutter apps ?
Thank you!
Vivien
Hi Vivien Cuisinier,
We don't have any additional changes needed for deploying Flutter PdfViewer on the windows platform. Kindly refer to the following KB to load the PDF document from the network in SfPdfViewer,
We have prepared the screen record of the output in the windows platform for your reference, which can be downloaded from the following link,
https://www.syncfusion.com/downloads/support/directtrac/general/ze/F174262-710155482.zip
Flutter PdfViewer runs on Windows 64-bit machine. So kindly share with us the following details,
1. Device Specification.
2. Flutter Doctor log.
3. syncfusion_flutter_pdfviewer package version.
This information will be helpful for us to provide you with a prompt solution at the earliest.
Regards,
Deepika Ravi
Hi Deepika,
The synfusion demo is wokring on my computer, but not my code. I am trying to identify the differences.
The version of syncfusion_flutter_pdfviewer package is different,
In the meantime, here below my details.
Many thanks for your help
1/
2/ Flutter doctor:
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 2.10.3, on Microsoft Windows [version 10.0.19044.1586], locale fr-CH)
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.0.5)
[√] Android Studio (version 2021.1)
[√] IntelliJ IDEA Community Edition (version 2021.3)
[√] VS Code, 64-bit edition (version 1.23.1)
[√] Connected device (3 available)
[√] HTTP Host Availability
3/ syncfusion_flutter_pdfviewer: ^19.4.50-beta
Hi,
I have just upgraded to the last version, I still get the same issue.
Best regards,
Vivien
syncfusion_flutter_pdfviewer: ^20.1.48-beta.1
Hi Vivien,
Hi,
I can reproduce the issue with a few lines of code in my main.dart.
However, in your demo app (https://github.com/syncfusion/flutter-widgets/tree/master/packages/syncfusion_pdfviewer_windows/example ), if I replace your main.dart by my main.dart, it is working (the issue disappears)
Conclusion : the issue is not in my dart code.
1/ Any idea where the root cause could hide?
2/ What do you want me to share exactly? I send you a zip file with most of my project file, I hope it helps.
Best regards,
Hi Vivien Cuisinier,
We tried to reproduce the reported issue with provided details, but the PDF is loaded properly on the Windows platform. We have prepared a sample for your reference and it can be downloaded at the following link, https://www.syncfusion.com/downloads/support/directtrac/general/ze/flutter_app_pdfviewer_sample-1730517783.zip
If you still reproduce the reported issue in your use case, then kindly share the modified issue reproducing in the sample which will be helpful for us to provide a prompt solution at the earliest.
Regards,
Deepika Ravi
I am having a similar issue to the original message on the web. I have included the script tag in my index.html to import pdf.js. I even tried to upgrade it to the latest version of pdf.js (2.16.105) but a PDF that loads fine on localhost fails to load on my hosting server. It is not a CORS issue because I am first downloading the file using the http package, then using the SfPdfViewer.memory() constructor to show the document. And all I can get in the onDocumentFailed callback is "There was an error opening this document." without any other details. And again, the weird part is that the very same document loads fine on localhost but fails on the server.
If you want to try for yourself, you can go to https://synkro-staff-dev.web.app
Log in with [email protected]/password1!
Go to the side menu, then Documents.
Select any person on the left hand side and tap a PDF document on the right hand side.
Once the document is loaded, the SfPdfViewer is shown and the console shows the error I get from onDocumentFailed.
Any idea why this could be? Is it possible to have more information in the onDocumentFailed callback?
Hi Sebastien,
We are checking on the reported query and will update the further details on September 30, 2022. Meanwhile, kindly share the following details,
Methodology used for hosting.
PDF document which you are using the application.
The provided URL is not opened properly it shown only a white screen.
This information will be helpful for us to provide you with a prompt solution at the earliest.
Regards,
Deepika Ravi
I'm hosting this Flutter web application on Firebase hosting
Here is a link to a PDF that's failing (they are all failing to load): https://www.dropbox.com/s/m8kucoi8sxoo6e1/SebastienArbogast_en.pdf?dl=0
Did you wait for a few seconds for the application to load?
Hi Sebastien,
Thank you for the details.
As we mentioned earlier, we are checking on this and will update the details on September 30 ,2022.
Regarding Did you wait for a few seconds for the application to load?
Yes, I wait for few minutes but only the white page is shown for your reference, I have attached the application output screenshot in the following link,
https://www.syncfusion.com/downloads/support/directtrac/general/SC60F1~1-119692698.png
Regards,
Deepika Ravi
I think I identified the problem. I was deploying my web app with
canvaskit rendering but since I removed this and built it with auto
rendering, it works now.
Hi Sebastien,
Thank you for the update. We are glad to know that the reported issue resolved at your end. Please feel free to contact us if you need any further assistance.
Regards,
Deepika R