typst_flutter 1.1.1 copy "typst_flutter: ^1.1.1" to clipboard
typst_flutter: ^1.1.1 copied to clipboard

Embed the Typst typesetting compiler natively in Flutter via Rust FFI. Compile Typst markup to PDF or rendered images on Android, iOS.

typst_flutter #

Pub Version Pub Points style: very good analysis License

Embed the Typst typesetting compiler natively into your Flutter apps via Rust FFI.

Compile Typst markup to high-quality PDF documents or rendered images on Android, iOS, macOS, Windows, and Linux. No WASM overhead, no WebView, no server required.

Features #

  • Native Performance: Typst runs directly on the device using a Rust core, compiling most documents in under 100ms.
  • Widgets Included: Drop-in TypstDocumentViewer and TypstView widgets for instant live previews.
  • Structured Error Handling: Get detailed TypstDiagnostic error lines when Typst compilation fails, perfect for building in-app editors.
  • Virtual File System: Pass Flutter assets and raw memory bytes directly into the Typst compiler via FontSource.

Getting started #

Add the package to your pubspec.yaml:

dependencies:
  typst_flutter: ^1.0.0

That's it! When you run flutter build or flutter run, the platform build scripts (Gradle/CocoaPods) will automatically fetch the correct native binaries for your architecture in the background.

Usage #

Rendering a PDF #

Use TypstCompiler.create() to initialize the engine and build documents:

import 'package:typst_flutter/typst_flutter.dart';

final compiler = await TypstCompiler.create();

final doc = await compiler.compile(
  source: r'''
    #set page(width: 148mm, height: 210mm, margin: 1cm)
    = Hello Typst!

    This is rendered *natively* in Flutter.
  ''',
);

print('Generated a ${doc.pageCount}-page PDF (${doc.pdf.length} bytes).');
// You can now save doc.pdf to disk or share it!

Live Preview Widget #

The TypstDocumentViewer widget automatically compiles and renders your document, providing a scrollable, zoomable UI. It caches compiled pages internally for butter-smooth scrolling.

import 'package:flutter/material.dart';
import 'package:typst_flutter/typst_flutter.dart';

class MyEditor extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return TypstDocumentViewer(
      source: r'''
        = Multi-page Viewer
        This document spans multiple pages.
        #pagebreak()
        And scrolling is instantly fast because the document is cached!
      ''',
      useSvg: true, // Use SVG for crisp vector text
    );
  }
}

Advanced Fallback (Cargokit) #

If you are building for a custom architecture or operating completely offline, the auto-download mechanism will gracefully fail and fall back to compiling the Rust core from source using Cargokit.

Note: Source compilation requires a full Rust toolchain (rustup) installed on your build machine and may take 5–15 minutes on the first run.

Testing #

Because this package relies on native Rust libraries via FFI, unit tests must be run as integration tests against a host platform.

flutter test integration_test/simple_test.dart

Author #

Ajmal (@ajmalbuv)

0
likes
160
points
236
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Embed the Typst typesetting compiler natively in Flutter via Rust FFI. Compile Typst markup to PDF or rendered images on Android, iOS.

Repository (GitHub)
View/report issues

Topics

#pdf #typst #document #typesetting #ffi

License

Apache-2.0 (license)

Dependencies

archive, crypto, flutter, flutter_rust_bridge, flutter_svg, http, path, plugin_platform_interface

More

Packages that depend on typst_flutter

Packages that implement typst_flutter