-
-
Notifications
You must be signed in to change notification settings - Fork 585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Build pdf with images included #51
Comments
Use: PdfImage image = await pdfImageFromImageProvider(
pdf: document,
image: AssetImage('assets/images/1.jpg'),
);
|
this is the only way? the printing package conflicts with firestore messaging and i need firestore messaging. is there no other way to do it without printing package? |
This is the error i receive the minute i add printing package to yaml :
|
changing my minSDK to 19 does not fix the issue. changing my firestore messaging version does nothing and changing printing packing version also does nothing, |
Just copy the function in your project then: /// Loads an image from a Flutter [ImageProvider]
/// into a [PdfImage] instance
Future<PdfImage> pdfImageFromImageProvider(
{@required PdfDocument pdf,
@required ImageProvider image,
ImageConfiguration configuration,
ImageErrorListener onError}) async {
final Completer<PdfImage> completer = Completer<PdfImage>();
final ImageStream stream =
image.resolve(configuration ?? ImageConfiguration.empty);
Future<void> listener(ImageInfo image, bool sync) async {
final PdfImage result =
await pdfImageFromImage(pdf: pdf, image: image.image);
if (!completer.isCompleted) {
completer.complete(result);
}
stream.removeListener(listener);
}
void errorListener(dynamic exception, StackTrace stackTrace) {
if (!completer.isCompleted) {
completer.complete(null);
}
if (onError != null) {
onError(exception, stackTrace);
} else {
FlutterError.reportError(FlutterErrorDetails(
context: 'image failed to load',
library: 'printing',
exception: exception,
stack: stackTrace,
silent: true,
));
}
}
stream.addListener(listener, onError: errorListener);
return completer.future;
} |
Thanks! Works perfectly. I didn't think of simply tearing the function out of the pack as an option!
|
This no longer works on the latest stable version of flutter version |
You can copy the updated function from the source here. |
got it. |
Dave, The web impl gives this error: Image.toByteData is not supported in Flutter for Web Is there a web-friendly way to convert the image to bytes ? Ian |
Describe the bug
I have been trying for days now and i cannot seem to add an image with my pdf document. When i run the function that creates the pdf, the text shows in the pdf perfectly, but the image shows as a black square.
To Reproduce
Steps to reproduce the behavior:
Enter code below ::
Am i doing something wrong here?
Expected behavior
Pdf document would include the jpg or png image.
Smartphone (please complete the following information):
Additional context
cant use the printing plugin along with firebase messaging. it doesn't compile.
The text was updated successfully, but these errors were encountered: