flutter_html_to_pdf_plus

Creator: coderz1093

Last updated:

Add to Cart

Description:

flutter html to pdf plus

flutter_html_to_pdf_plus #

Flutter plugin for generating PDF files from HTML
Usage #
From a raw HTML content
var targetPath = "/your/sample/path";
var targetFileName = "example_pdf_file"

var generatedPdfFile = await FlutterHtmlToPdf.convertFromHtmlContent(
content: htmlContent,
configuration: PdfPrinterConfiguration(
targetPath: targetPath,
targetFileName: targetFileName,
margins: PdfPrinterMargins(top: 10, bottom: 10, left: 10, right: 10),
orientation: PrintOrientation.Landscape,
printSize: PrintSize.A4
),
);
copied to clipboard
From an HTML file
var file = File("/sample_path/example.html");
var generatedPdfFile = await FlutterHtmlToPdf.convertFromHtmlFile(
htmlFile: file,
configuration: PdfPrinterConfiguration(
targetPath: targetPath,
targetFileName: targetFileName,
margins: PdfPrinterMargins(top: 10, bottom: 10, left: 10, right: 10),
orientation: PrintOrientation.Landscape,
printSize: PrintSize.A4
),
);
copied to clipboard
From an HTML file path
var filePath = "/sample_path/example.html";
var generatedPdfFile = await FlutterHtmlToPdf.convertFromHtmlFilePath(
htmlFilePath: filePath,
configuration: PdfPrinterConfiguration(
targetPath: targetPath,
targetFileName: targetFileName,
margins: PdfPrinterMargins(top: 10, bottom: 10, left: 10, right: 10),
orientation: PrintOrientation.Landscape,
printSize: PrintSize.A4
),
);
copied to clipboard

/!\ Caveats : Customization of orientation is not supported on iOS. Any config will be ignored.

Images
If your want to add local image from device to your HTML you need to pass path to image as src value.
<img src="file:///storage/example/your_sample_image.png" alt="web-img">
copied to clipboard
or if you want to use the image File object
<img src="${imageFile.path}" alt="web-img">
copied to clipboard
Many images inside your document can significantly affect the final file size so we suggest to use flutter_image_compress plugin to compress images before generating PDF.
Contributing #
If you want to contribute, please submit a pull request or create an issue.
Credits #

Thanks to Afur for the initial work on this plugin
Thanks to raister21 for their work on PDF Size & Orientation
Thanks to wiseminds for the inspiration for margins customization

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.