# Create PDFs from HTML in Flutter

[`Nutrient`](https://pub.dev/documentation/nutrient_flutter/latest/nutrient_flutter/Nutrient-class.html) provides powerful APIs for generating PDF files directly from HTML strings and URIs. It relies on the [WebView](https://developer.android.com/reference/android/webkit/WebView) system for Android and [WebKit](https://webkit.org/) for the iOS implementation. This means there are certain aspects of the conversion process that Nutrient cannot support. This includes, for example, any possible [WebView](https://developer.android.com/reference/android/webkit/WebView) or [WebKit](https://webkit.org/) bugs. The following examples show how to generate a PDF from an HTML string and URI/URL.

## License

To generate a PDF from HTML, [contact Sales](https://www.nutrient.io/contact-sales) to add HTML-to-PDF conversion to your license.

## Generating a PDF from an HTML string

The code below shows how to generate a PDF from an HTML string:

```dart

const html = '''
<html>
    <head>
        <style type="text/css">
            h1 {
                color: red;
            }
        </style>
    </head>
    <body>
        <h1>Hello, world!</h1>
    </body>
</html>
''';

// Writable output path.
final outputFilePath = '<writable-output-file-path>'

// Generate the PDF from the HTML string.
String? generatedPdf = await Nutrient.generatePdfFromHtmlString(html, outputFilePath);
if (generatedPdf == null) {
    print('Failed to generate PDF from HTML string.');
    return;
}

// Display the generated PDF.
await Nutrient.present(generatedPdf);

```

## Generating a PDF from an HTML URL/URI

The code below shows how to generate a PDF from an HTML URL or URI:

```dart

// Writable output path.
final htmlUrl =  Uri.parse('https://pspdfkit.com');
final outputFilePath = <writable-output-path>;

   // Generate the PDF from the HTML URL.
   String? generatedPdf = await Nutrient.generatePdfFromHtmlUri(htmlUri, outputFilePath);

   if (generatedPdf == null) {
   print('Failed to generate PDF from HTML URI.');
   return;
   }

   // Display the generated PDF.
   await Nutrient.present(generatedPdf);

```

For more information on generating PDF files from HTML strings and URLs, see the [`Nutrient`](https://pub.dev/documentation/nutrient_flutter/latest/nutrient_flutter/Nutrient-class.html) API reference and the [PDF Generation Example](https://github.com/PSPDFKit/pspdfkit-flutter/blob/master/example/lib/pdf_generation_example.dart) from the [Catalog app](https://github.com/PSPDFKit/pspdfkit-flutter).
---

## Related pages

- [Generate a blank PDF in Flutter](/guides/flutter/pdf-generation/blank-pdf.md)
- [Generate a PDF from an image in Flutter](/guides/flutter/pdf-generation/from-images.md)
- [Generate a PDF from a template in Flutter](/guides/flutter/pdf-generation/from-template.md)
- [PDF Generation library for Flutter](/guides/flutter/pdf-generation.md)

