Add PDF functionality with Flutter
Nutrient Web SDK is a JavaScript PDF library for viewing, annotating, and editing PDFs directly in the browser. Use it to add PDF capabilities to any web app.
This guide walks you through the steps to integrate Nutrient Web SDK into your project. By the end, you’ll be able to render a PDF document in the user interface (UI).
You can test the SDK capabilities in our playground.
Prefer to jump straight into code? View the example repo on GitHub.
Installing the Nutrient dependency
You can load Nutrient Web SDK directly from Nutrient’s content delivery network (CDN). Nutrient maintains the CDN for customers, and it’s our recommended way to get started. For more control and flexibility, use the local installation option.
Add the following
scripttag to the<head>section of yourweb/index.htmlfile:<script src="https://cdn.cloud.pspdfkit.com/pspdfkit-web@1.9.1/nutrient-viewer.js"></script>You’re now ready to use Nutrient Web SDK and reference
window.NutrientViewerin the client-side code.
Add the Nutrient Web SDK (
@nutrient-sdk/viewer) dependency:If you tried CDN installation first, make sure to remove the script tag:
web/index.html <script src="https://cdn.cloud.pspdfkit.com/pspdfkit-web@1.9.1/nutrient-viewer.js"></script>You’re now ready to use Nutrient Web SDK locally in your Flutter app.
Rendering a PDF
Import the
PSPDFKitpackage:import 'package:nutrient_flutter/nutrient_flutter.dart';Display a PDF document inside your Flutter app:
Scaffold(body: NutrientView(documentPath: 'https://www.nutrient.io/downloads/nutrient-web-demo.pdf',),);Run the app:
Terminal window flutter run
Import the
PSPDFKitpackage:import 'package:nutrient_flutter/nutrient_flutter.dart';Display a PDF document inside your Flutter app:
Scaffold(body: NutrientView(documentPath: 'https://www.nutrient.io/downloads/nutrient-web-demo.pdf',),);Optional: If you decide to self-host the Nutrient Web SDK assets as described in this guide, you can configure the
baseUrl. Refer to the Flutter Web SDK integration documentation(opens in a new tab) for details on configuring the base URL in your Flutter web project.If you don’t set a
baseUrl, the SDK will load assets from the CDN by default.Run the app:
Terminal window flutter run
Troubleshooting
If you encounter issues, refer to the common issues guide.
Note for developers using AI coding assistants: To get accurate troubleshooting help, copy the content from the troubleshooting guide and include it in your prompt, along with your specific error.
You can test the SDK capabilities in our playground.
Prefer to jump straight into code? View the example repo on GitHub.