htmltopdfwidgets 1.0.5 htmltopdfwidgets: ^1.0.5 copied to clipboard
Htmlt to pdf widgets library convert html text to pdf widgets
import 'dart:io';
import 'package:htmltopdfwidgets/htmltopdfwidgets.dart';
void main() {
createDocument();
}
const htmlText = '''<h1>AppFlowyEditor</h1>
<h2>👋 <strong>Welcome to</strong> <strong><em><a href="appflowy.io">AppFlowy Editor</a></em></strong></h2>
<p>AppFlowy Editor is a <strong>highly customizable</strong> <em>rich-text editor</em></p>
<hr />
<p><u>Here</u> is an example <del>your</del> you can give a try</p>
<br>
<span style="font-weight: bold;background-color: #cccccc;font-style: italic;">Span element</span>
<span style="font-weight: medium;text-decoration: underline;">Span element two</span>
</br>
<span style="font-weight: 900;text-decoration: line-through;">Span element three</span>
<a href="https://appflowy.io">This is an anchor tag!</a>
<img src="https://images.squarespace-cdn.com/content/v1/617f6f16b877c06711e87373/c3f23723-37f4-44d7-9c5d-6e2a53064ae7/Asset+10.png?format=1500w" />
<h3>Features!</h3>
<ul>
<li>[x] Customizable</li>
<li>[x] Test-covered</li>
<li>[ ] more to come!</li>
</ul>
<ol>
<li>First item</li>
<li>Second item</li>
</ol>
<li>List element</li>
<blockquote>
<p>This is a quote!</p>
</blockquote>
<code>
Code block
</code>
<em>Italic one</em> <i>Italic two</i>
<b>Bold tag</b>
<img src="http://appflowy.io" alt="AppFlowy">
<p>You can also use <strong><em>AppFlowy Editor</em></strong> as a component to build your own app.</p>
<h3>Awesome features</h3>
<p>If you have questions or feedback, please submit an issue on Github or join the community along with 1000+ builders!</p>
<h3>Checked Boxes</h3>
<input type="checkbox" id="option2" checked>
<label for="option2">Option 2</label>
<input type="checkbox" id="option3">
<label for="option3">Option 3</label>
''';
const String markDown = """
# Basic Markdown Demo
---
The Basic Markdown Demo shows the effect of the four Markdown extension sets
on formatting basic and extended Markdown tags.
## Overview
The Dart [markdown](https://pub.dev/packages/markdown) package parses Markdown
into HTML. The flutter_markdown package builds on this package using the
abstract syntax tree generated by the parser to make a tree of widgets instead
of HTML elements.
The markdown package supports the basic block and inline Markdown syntax
specified in the original Markdown implementation as well as a few Markdown
extensions. The markdown package uses extension sets to make extension
management easy. There are four pre-defined extension sets; none, Common Mark,
GitHub Flavored, and GitHub Web. The default extension set used by the
flutter_markdown package is GitHub Flavored.
The Basic Markdown Demo shows the effect each of the pre-defined extension sets
has on a test Markdown document with basic and extended Markdown tags. Use the
Extension Set dropdown menu to select an extension set and view the Markdown
widget's output.
## Comments
Since GitHub Flavored is the default extension set, it is the initial setting
for the formatted Markdown view in the demo.
""";
createDocument() async {
const filePath = 'html_example.pdf';
const markDownfilePath = 'markdown_example.pdf';
final file = File(filePath);
final markdownfile = File(markDownfilePath);
final newpdf = Document();
final markdownNewpdf = Document();
final List<Widget> widgets = await HTMLToPdf().convert(
htmlText,
);
final List<Widget> markdownwidgets = await HTMLToPdf().convertMarkdown(
markDown,
);
newpdf.addPage(MultiPage(
maxPages: 200,
build: (context) {
return widgets;
}));
markdownNewpdf.addPage(MultiPage(
maxPages: 200,
build: (context) {
return markdownwidgets;
}));
await file.writeAsBytes(await newpdf.save());
await markdownfile.writeAsBytes(await markdownNewpdf.save());
}