html_to_pdf_plus

Last updated:

0 purchases

html_to_pdf_plus Image
html_to_pdf_plus Images
Add to Cart

Description:

html to pdf plus

html_to_pdf_plus #


Flutter plugin for generating PDF files from HTML

Screenshots #


Usage #

final htmlContent = """
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td, p {
padding: 5px;
text-align: left;
}
</style>
</head>
<body>
<h2>PDF Generated with html_to_pdf_plus plugin</h2>

<table style="width:100%">
<caption>Sample HTML Table</caption>
<tr>
<th>Portfolio</th>
<th>Link</th>
</tr>
<tr>
<td>Website</td>
<td><a href="https://khizarrehman.com/">https://khizarrehman.com/</a></td>
</tr>
<tr>
<td>Fiverr</td>
<td><a href="https://www.fiverr.com/ranakhizar">https://www.fiverr.com/ranakhizar</a></td>
</tr>
</table>

<img src="https://avatars.githubusercontent.com/u/32544554?v=4" alt="web-img">
</body>
</html>
""";

var targetPath = "/your/sample/path";
var targetFileName = "example_pdf_file";

final generatedPdfFile = await HtmlToPdf.convertFromHtmlContent(
htmlContent: htmlContent,
configuration: PdfConfiguration(
targetDirectory: targetPath,
targetName: targetFileName,
printSize: PrintSize.A4,
printOrientation: PrintOrientation.Landscape,
linksClickable: true
));

copied to clipboard

Code above simply generates PDF file from HTML content. It should work with most of common HTML markers. You don’t need to add .pdf extension to targetFileName because plugin only generates PDF files and extension will be added automatically.
Other Usages

You can also pass File object with HTML content inside as parameter
var file = File("/sample_path/example.html");
var generatedPdfFilee = await HtmlToPdf.convertFromHtmlFile(
htmlFile: file,
configuration: PdfConfiguration(
targetDirectory: targetPath,
targetName: targetFileName,
printSize: PrintSize.A4,
printOrientation: PrintOrientation.Portrait,
linksClickable: true
));
copied to clipboard
or even just path to this file
var filePath = "/sample_path/example.html";
var generatedPdfFilee = await HtmlToPdf.convertFromHtmlFilePath(
htmlFilePath: filePath,
configuration: PdfConfiguration(
targetDirectory: targetPath,
targetName: targetFileName,
printSize: PrintSize.A4,
printOrientation: PrintOrientation.Portrait,
linksClickable: true
));
copied to clipboard
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 I suggest to use flutter_image_compress plugin.

License:

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

Customer Reviews

There are no reviews.