---
title: "Flutter open PDF file | Nutrient SDK"
canonical_url: "https://www.nutrient.io/guides/flutter/open-a-document/"
md_url: "https://www.nutrient.io/guides/flutter/open-a-document.md"
last_updated: "2025-07-02T00:00:00.000Z"
description: "Open PDF files in your Flutter app using Nutrient Flutter SDK. Learn to copy assets to a temporary directory and display documents with NutrientView, present(), or headless processing."
---

# Open PDF files in Flutter

Nutrient Flutter SDK enables you to open documents using `NutrientView`, the `Nutrient.present()` method, or headless processing with `Nutrient.openDocument()`.

## Opening a PDF with a viewer

To open a PDF file stored as an asset, first copy it to a temporary directory.

The following helper function copies the file to a temporary directory:

```dart

Future<File> extractAsset(String assetPath) async {
    // On Web, we can directly use the asset path.
    if (kIsWeb) return File(assetPath);

    final bytes = await DefaultAssetBundle.of(context).load(assetPath);
    final list = bytes.buffer.asUint8List();

    final tempDir = await Nutrient.getTemporaryDirectory();
    final tempDocumentPath = '${tempDir.path}/$assetPath';

    final file = await File(tempDocumentPath).create(recursive: true);
    file.writeAsBytesSync(list);
    return file;
}

```

To open a PDF document using `NutrientView`:

```dart

final extractedDocument = await extractAsset(_documentPath);

Scaffold(
    extendBodyBehindAppBar: true,
    appBar: AppBar(),
    body: NutrientView(documentPath: extractedDocument.path),
);

```

To open a PDF document using the global `present()` method:

```dart

final document = await extractAsset(documentPath);
await Nutrient.present(document.path);

```

The `present()` method is a global method that works from anywhere in the app. It’s only supported on iOS and Android.

For more details about how to open a document using Nutrient Flutter SDK, see our [getting started](https://www.nutrient.io/sdk/flutter/getting-started.md) guides or try our [Catalog example project](https://www.nutrient.io/sdk/flutter/getting-started.md).

## Opening an image

In addition to PDF documents, Nutrient Flutter SDK also enables you to open and annotate images (PNG and JPEG). The following example shows how to open a PNG image using the `present()` method:

```dart

final extractedImage = await extractAsset(imagePath);
await Nutrient.present(extractedImage.path);

```

## Document loaded callback

Use the `onDocumentLoaded` callback to get notified when a document has been loaded. This is called with the [`PdfDocument`](https://pub.dev/documentation/nutrient_flutter/latest/nutrient_flutter/PdfDocument-class.html) object as an argument:

```dart

NutrientView(
    documentPath: extractedDocument.path,
    onDocumentLoaded: (PdfDocument pdfDocument) {
        print('Document loaded: ${pdfDocument.documentId}');
    },
);

```

## Headless processing

Use `Nutrient.openDocument()` to open and manipulate PDF documents without displaying a viewer user interface (UI):

```dart

import 'package:nutrient_flutter/nutrient_flutter.dart';

void processDocument(String documentPath) async {
  final document = await Nutrient.openDocument(documentPath);

  try {
    final pageCount = await document.getPageCount();
    print('Document has $pageCount pages');

    // Perform operations...
  } finally {
    await document.close();
  }
}

```

For password-protected documents:

```dart

final document = await Nutrient.openDocument(
  documentPath,
  password: 'secret123',
);

```

### Available operations

With a `PdfDocument` instance, the following operations are available:

- **Annotations** — `getAnnotations()`, `addAnnotation()`, `removeAnnotation()`, `processAnnotations()`

- **Form fields** — `getFormFields()`, `getFormFieldValue()`, `setFormFieldValue()`

- **Bookmarks** — `getBookmarks()`, `addBookmark()`, `removeBookmark()`

- **Export/Import** — `exportInstantJson()`, `applyInstantJson()`, `exportXfdf()`, `importXfdf()`, `exportPdf()`

### Saving and closing

Headless documents require explicit saving and closing:

```dart

final hasChanges = await document.hasUnsavedChanges();
if (hasChanges) {
  await document.save();
}
await document.close();

```

### Headless vs. viewer

The following table compares headless processing with the viewer:

| Feature          | Headless           | Viewer    |
| ---------------- | ------------------ | --------- |
| UI displayed     | No                 | Yes       |
| Auto-save        | No                 | Yes       |
| Resource cleanup | Manual (`close()`) | Automatic |
---

## Related pages

- [Agent skill](/guides/flutter/agent-skill.md)
- [Flutter PDF bookmark SDK](/guides/flutter/bookmarks.md)
- [Dart PDF library](/guides/flutter/dart.md)
- [Bridge Nutrient native Android, iOS, and Web APIs in Flutter](/guides/flutter/customize.md)
- [Explore advanced PDF capabilities with demos](/guides/flutter/demo.md)
- [Changelog for Flutter](/guides/flutter/changelog.md)
- [Download Flutter library](/guides/flutter/downloads.md)
- [Flutter PDF library](/guides/flutter.md)
- [Flutter guides: Integrate our PDF library](/guides/flutter/intro.md)
- [Knowledge base](/guides/flutter/kb.md)
- [Upgrade and migration guides](/guides/flutter/upgrade.md)

