dart_pdf
dart_pdf copied to clipboard
Unable to display the document, after deploy to web browser
Describe the bug
the bug occurs if you have done a flutter build web and deployed it in the browser and the results are like this even though it was run in testing mode successfully but here it doesn't work
To Reproduce Code snippet to reproduce the behavior:
in code web/index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
<meta name="description" content="Rakuraku Flutter.">
<!-- iOS meta tags & icons -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="rakuraku">
<link rel="apple-touch-icon" href="icons/Icon-192.png">
<!-- Favicon -->
<link rel="shortcut icon" type="image/png" href="favicon.png"/>
<title>rakuraku</title>
<link rel="manifest" href="manifest.json">
</head>
<body id="flutter">
<!-- This script installs service_worker.js to provide PWA functionality to
application. For more information, see:
https://developers.google.com/web/fundamentals/primers/service-workers -->
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', function () {
navigator.serviceWorker.register('flutter_service_worker.js');
});
}
</script>
<script src="//cdnjs.cloudflare.com/ajax/libs/pdf.js/2.7.570/pdf.min.js"></script>
<script type="text/javascript">
pdfjsLib.GlobalWorkerOptions.workerSrc = "//cdnjs.cloudflare.com/ajax/libs/pdf.js/2.7.570/pdf.worker.min.js";
</script>
<script src="main.dart.js" type="application/javascript"></script>
</body>
</html>
Expected behavior
local testing went well
Screenshots Web Browser LOCAL TESTING
Screenshots Web Browser
Flutter Doctor
[✓] Flutter (Channel stable, 3.7.8, on macOS 13.5 22G74 darwin-arm64 (Rosetta), locale en-ID)
• Flutter version 3.7.8 on channel stable at /Users/mac/Documents/development/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 90c64ed42b (11 months ago), 2023-03-21 11:27:08 -0500
• Engine revision 9aa7816315
• Dart version 2.19.5
• DevTools version 2.20.1
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at /Users/mac/Library/Android/sdk
• Platform android-34, build-tools 34.0.0
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 15A507
• CocoaPods version 1.14.3
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2022.3)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
[✓] VS Code (version 1.84.2)
• VS Code at /Users/mac/Downloads/Visual Studio Code.app/Contents
• Flutter extension version 3.82.0
[✓] Connected device (2 available)
• macOS (desktop) • macos • darwin-arm64 • macOS 13.5 22G74 darwin-arm64 (Rosetta)
• Chrome (web) • chrome • web-javascript • Google Chrome 121.0.6167.160
! Error: Browsing on the local area network for mac-sirs’s iPhone. Ensure the device is
unlocked and attached with a cable or associated with the same local area network as this
Mac.
The device must be opted into Developer Mode to connect wirelessly. (code -27)
! Error: Browsing on the local area network for Nurul Miwu. Ensure the device is unlocked
and attached with a cable or associated with the same local area network as this Mac.
The device must be opted into Developer Mode to connect wirelessly. (code -27)
[✓] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
Desktop (please complete the following information):
- [ ] iOS
- [ ] Android
- [x] Browser
- [ ] Windows
- [ ] Linux
Smartphone (please complete the following information):
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari, chrome]
- Version [e.g. 22]
Additional context
Hi @somadzakaria!
Up until very recently, I had the same problem and the solution was to use the master branch version. To do this, add the following to your pubspec.yaml:
dependency_overrides:
pdf:
git:
url: https://github.com/DavBfr/dart_pdf.git
path: pdf
ref: master
I'm having this same problem. I tried what @wbasabe0891201 recommended with no success. I am trying to load an existing pdf I have in assets and display/print it. This happens on button press.
Here is my code to push the PdfPreview:
Navigator.of(context).push(
MaterialPageRoute(
builder: (_) {
return PdfPreview(
build: (format) => rootBundle
.load('assets/pdf/my_pdf.pdf')
.then((value) => value.buffer.asUint8List()));
},
),
);
This works when I build and run locally, but as soon as I deploy the built code to my website, I get the same result as @somadzakaria .
thanks for solution, this code its work and
same problem here
This may help: https://github.com/DavBfr/dart_pdf/issues/1614#issuecomment-2093460760