html_pdf_widgets 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, headings, and many more.
The package was built upon the htmltopdfwidgets package by simplifying the code, adding more features, and fixing bugs.
- Convert HTML content to PDF documents in Flutter apps
- Support for Rich Text Editor formats
- Seamless integration with your Flutter project
- Lightweight and easy to use
Add the following dependency to your pubspec.yaml
file:
dependencies:
html_pdf_widgets: <latest version>
To use html_pdf_widgets in your Flutter project, follow these simple steps:
- Import the package:
import 'package:vsc_html_pdf_widgets/html_pdf_widgets.dart';
- Convert HTML to PDF:
final htmlContent = '''
<h1>Heading Example</h1>
<p>This is a paragraph.</p>
<img src="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 document = Document();
List<Widget> widgets = await HTMLToPdf().convert(htmlContent);
document.addPage(
MultiPage(
maxPages: 200,
build: (context) => widgets
)
);
await file.writeAsBytes(await document.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.