HTMLtoPDFWidgets is a Flutter package that allows you to convert HTML content into PDF documents with support for various Rich Text Editor formats. With this package, you can effortlessly generate PDF files that include elements such as lists, paragraphs, images, quotes, and headings.
Add the following dependency to your pubspec.yaml
file:
dependencies:
htmltopdfwidgets: ^0.0.9+1
To use HTMLtoPDFWidgets in your Flutter project, follow these simple steps:
import 'package:htmltopdfwidgets/htmltopdfwidgets.dart';
final htmlContent = '''
<h1>Heading Example</h1>
<p>This is a paragraph.</p>
<img src="https://github.com/alihassan143/htmltopdfwidgets/raw/main/image.jpg" alt="Example Image" />
<blockquote>This is a quote.</blockquote>
<ul>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
</ul>
''';
var filePath = 'test/example.pdf';
var file = File(filePath);
final newpdf = Document();
List<Widget> widgets = await HTMLToPdf().convert(htmlContent);
newpdf.addPage(MultiPage(
maxPages: 200,
build: (context) {
return widgets;
}));
await file.writeAsBytes(await newpdf.save());
For more details on usage and available options, please refer to the API documentation.
You can find a complete example in the example directory of this repository.
This package is licensed under the MIT License.
Contributions are welcome! If you encounter any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request on the GitHub repository.
Special thanks to the Appflowy editor: I use their Html To Document plugin as reference
Happy PDF generation with HTMLtoPDFWidgets in your Flutter apps!
I've been maintaining quite many repos these days and burning out slowly. If you could help me cheer up, buying me a cup of coffee will make my life really happy and get much energy out of it.