packages.flutter
packages.flutter copied to clipboard
Web "Exception: Unknown Error"
Describe the bug This code:
class PDFWidget extends StatelessWidget {
final String path;
final Future<PdfDocument>_page;
late final PdfControllerPinch _controller;
PDFWidget({
required
String this.path,
Key? key
}):
_page = path.startsWith('http')
? PdfDocument.openData(InternetFile.get(path)) : PdfDocument.openAsset(path),
super(key: key) {
_controller = PdfControllerPinch(document: _page);
}
@override
Widget build(BuildContext context) {
return PdfViewPinch(controller: _controller);
}
}
works fine on desktop and mobile, but all I see where the pdf should be in web is "Exception: Unknown Error".
To Reproduce Steps to reproduce the behavior:
- Set up assets with a pdf
- Render the above object with a suitable asset path.
Expected behavior The pdf should display.
Additional context MacOS M1.
Flutter (Channel stable, 2.10.3, on macOS 12.2.1 21D62 darwin-arm, locale en-US) • Flutter version 2.10.3 at /opt/homebrew/Caskroom/flutter/2.2.1/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 7e9793dee1 (7 days ago), 2022-03-02 11:23:12 -0600 • Engine revision bd539267b4 • Dart version 2.16.1 • DevTools version 2.9.2
we are having the same issue in web also
@gisborne @DevFauche Please re-check installation guide.
- Runned or not command
flutter pub run pdfx:install_web
in project folder is have fileweb/index.html
same code: https://github.com/ScerIO/packages.flutter/blob/546ada85da994d1273f9208357ebda7a1f6435be/packages/pdfx/example/web/index.html#L35-L43 If code not exist add manually - Target host requires CORS policy. For example:
// Not works. www.africau.edu not support CORS for any hosts
PdfControllerPinch(
document: PdfDocument.openData(
InternetFile.get(
'http://www.africau.edu/images/default/sample.pdf',
),
),
);
// Works, proxy add header with CORS awailable for XHR request anywhere
PdfControllerPinch(
document: PdfDocument.openData(
InternetFile.get(
'https://api.codetabs.com/v1/proxy/?quest=http://www.africau.edu/images/default/sample.pdf',
),
),
);
@gisborne @DevFauche Please re-check installation guide.
Runned or not command
flutter pub run pdfx:install_web
in project folder is have fileweb/index.html
same code: https://github.com/ScerIO/packages.flutter/blob/546ada85da994d1273f9208357ebda7a1f6435be/packages/pdfx/example/web/index.html#L35-L43If code not exist add manually
Target host requires CORS policy. For example:
// Not works. www.africau.edu not support CORS for any hosts PdfControllerPinch( document: PdfDocument.openData( InternetFile.get( 'http://www.africau.edu/images/default/sample.pdf', ), ), ); // Works, proxy add header with CORS awailable for XHR request anywhere PdfControllerPinch( document: PdfDocument.openData( InternetFile.get( 'https://api.codetabs.com/v1/proxy/?quest=http://www.africau.edu/images/default/sample.pdf', ), ), );
The code in point one helped me to get the package working on web. Thanks. (I am only trying to load from assets directory)
The command flutter pub run pdfx:install_web
did not do anything in my project, but the output of the command showed "success"
The command
flutter pub run pdfx:install_web
did not do anything in my project, but the output of the command showed "success"
@SergeShkurko can you fix this?
Also seeing this - running the above command got me this:
[Modify web/index.hml by addition pdfjs]
Already installed, operation aborted
pub finished with exit code 2
In my case, the PDF is rendering fine in a local build but gives me a 404 when deployed. I also checked my index.html
and it has the script lines added in your above comment. Any updates or things to try @SergeShkurko ?