Scrivr
Packages

@scrivr/export

Export utilities — serialize Scrivr documents to paginated PDF (pdf-lib) or Markdown.

@scrivr/export provides serializers that convert an Scrivr EditorState into portable document formats. All serializers run entirely in the browser — no server round-trip required.

Installation

pnpm add @scrivr/export
npm install @scrivr/export
yarn add @scrivr/export

PDF Export

Generates a multi-page PDF that matches the paginated canvas layout. Powered by pdf-lib.

Currently uses standard PDF fonts (Helvetica, Times, Courier). Custom font embedding is coming soon — documents using custom font families will fall back to the standard fonts in the meantime.

import { exportToPdf } from '@scrivr/export';

const pdfBytes = await exportToPdf(editor);

// Download in the browser
const blob = new Blob([pdfBytes], { type: 'application/pdf' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'document.pdf';
a.click();

exportToPdf takes the editor instance and returns a Promise<Uint8Array> of the raw PDF bytes.


DOCX Export

DOCX export is coming soon. The exportToDocx function is exported but currently returns an empty document. Full Word-compatible export is on the roadmap.


Markdown Export

Converts the document to a CommonMark Markdown string. Useful for storing documents in version-controlled text files or feeding content into AI pipelines.

import { exportToMarkdown } from '@scrivr/export';

const markdown = exportToMarkdown(editor);
console.log(markdown);
// # Heading
//
// A paragraph with **bold** and _italic_ text.

exportToMarkdown is synchronous and returns a string.

Markdown has no equivalent for some Scrivr formatting. The following are silently dropped during serialization — the text content is preserved but the formatting is lost:

LostReason
Text alignment (left, center, right, justify)Not part of CommonMark
Font familyNot part of CommonMark
Font sizeNot part of CommonMark
Text colorNot part of CommonMark
HighlightNot part of CommonMark
Track Changes marksPending insertions/deletions are exported as plain text

If you need to round-trip a document without losing formatting, use the JSON format (editor.getJSON() / editor.setJSON()) or wait for DOCX export.


Export Guide

On this page