Docyrus

Record PDF Export

Three-step wizard (Select a Template → Preview → PDF) that renders a Docyrus record to PDF with a saved HTML template, previews the server-compiled document in a WebView, and shares or prints the result. Includes the headless useDocyrusRecordPdfExport hook.

iOSAndroid
Preview Record PDF Export on your device

Scan with Expo Go

Download Expo Go, then scan the QR code to preview native components.

Installation

pnpm dlx @docyrus/cli add @docyrus/rn-record-pdf-export
Required Packages(6 packages)
pnpm add @tanstack/react-query @docyrus/api-client react-native-webview 13.x (optional) expo-file-system (optional) expo-sharing (optional) expo-print (optional)

This is a Docyrus-connected component. It needs an authenticated RestApiClient and a QueryClientProvider above it.

All native modules are optional peers, loaded lazily:

ModuleUsed forWithout it
react-native-webviewThe Preview step, and the inline PDF on iOS.The preview shows an install notice; the PDF step shows the file card.
expo-file-systemDownloading the signed PDF into the cache directory.Share has nothing to share.
expo-sharingThe Share button (share sheet).Sharing is a no-op.
expo-printThe Print button, and rendering the compiled HTML to a PDF on the device when the server returns no public URL.The Print button is hidden.

Usage

Wizard in a sheet

import { useState } from 'react';

import { useDocyrusClient } from '@docyrus/signin/react-native';

import { AwesomeDialog, AwesomeDialogContent, AwesomeDialogHeader, AwesomeDialogBody } from '@/components/docyrus-native/awesome-dialog';
import { DocyrusRecordPdfExportWizard } from '@/components/docyrus-native/record-pdf-export';

export function ExportOrderPdf({ dataSourceId, recordId }: { dataSourceId: string; recordId: string }) {
  const client = useDocyrusClient();
  const [open, setOpen] = useState(false);

  return (
    <AwesomeDialog open={open} onOpenChange={setOpen} container="sheet" side="bottom" size="full">
      <AwesomeDialogContent>
        <AwesomeDialogHeader title="Export PDF" icon="fal file-pdf" />
        <AwesomeDialogBody>
          <DocyrusRecordPdfExportWizard
            client={client!}
            dataSourceId={dataSourceId}
            recordId={recordId}
            onClose={() => setOpen(false)}
            onShare={(result, uri) => console.log('shared', result.path, uri)} />
        </AwesomeDialogBody>
      </AwesomeDialogContent>
    </AwesomeDialog>
  );
}

Headless: build your own UI

import { useDocyrusRecordPdfExport } from '@/components/docyrus-native/record-pdf-export';

const pdf = useDocyrusRecordPdfExport({ client, dataSourceId, recordId });

// pdf.templates / pdf.setSelectedTemplateId → pick a template
// pdf.previewHtml → render in your own WebView
// await pdf.generatePdf() → server render; pdf.pdfUrl when signed
// await pdf.sharePdf() / pdf.printPdf()

How it works

  1. Resolve. Without appSlug / dataSourceSlug, the hook resolves them from GET /v1/dev/data-sources/{id}.
  2. Select a Template. Lists GET /v1/dev/html-templates?tenantDataSourceId=…. The default template (or the first one) is picked automatically unless autoSelectDefaultTemplate is false or initialTemplateId is set. Each row shows the name, a Default badge and page format / orientation.
  3. Preview. Loads the server-compiled document from GET /v1/apps/{app}/data-sources/{ds}/items/{recordId}/templates/{templateId}/html. previewHtml combines it with the template CSS and an A4 preview stylesheet, and the wizard renders it in a WebView.
  4. PDF. Pressing Next on the Preview step calls generatePdf(), which runs GET …/templates/{templateId}/pdf. The result ({ id, path, fullPath, url?, … }) is surfaced as is. On iOS, a signed url renders inline in the WebView. On Android, whose WebView cannot render PDFs, and when there is no url, a file card appears instead.
  5. Share / Print. sharePdf() downloads the signed url into the cache directory (or, without a url, renders the compiled HTML on the device with expo-print) and opens the share sheet. printPdf() opens the system print dialog.

API Reference

DocyrusRecordPdfExportWizardProps

Accepts every useDocyrusRecordPdfExport option plus:

PropTypeDefaultDescription
classNamestring—Root View classes.
bodyHeightnumber70% of the window heightHeight of the wizard (px).
onClose() => void—Fired by the footer Done button on the last step.
hideClosebooleanfalseHide the Done button.
onShare(result: DocyrusRecordPdfResult, uri: string) => void—Native: called after the PDF was handed to the share sheet (uri = local file).
enablePrintbooleantrueNative: show Print on the PDF step (needs expo-print).

Options (UseDocyrusRecordPdfExportOptions)

OptionTypeDefaultDescription
clientRestApiClient—Authenticated REST client (required).
dataSourceIdstring—tenant_data_source.id of the record's data source (required).
recordIdstring—tenant_data_source_item.id of the record (required).
appSlugstring—App slug. Resolved from dataSourceId when omitted.
dataSourceSlugstring—Data source slug. Resolved from dataSourceId when omitted.
enabledbooleantrueToggle all network activity.
initialTemplateIdstring—Pre-select a template by id.
autoSelectDefaultTemplatebooleantrueSelect the default (or first) template once the list loads.
resolveDataSourceEndpointstring'/v1/dev/data-sources/{id}'Slug resolution endpoint ({id} is replaced).
listTemplatesEndpointstring'/v1/dev/html-templates'Templates list endpoint.

Result (UseDocyrusRecordPdfExportResult)

FieldTypeDescription
stepsRecordPdfExportStep[]['select', 'preview', 'pdf'].
step / setStep / stepIndexRecordPdfExportStep / setter / numberCurrent step.
goNext / goBack() => voidStep navigation.
canGoNext / canGoBack / isLastStepbooleanNavigation state. canGoNext needs a selected template (select) or a loaded preview (preview).
appSlug / dataSourceSlugstring | nullResolved slugs.
isResolving / resolveErrorboolean / Error | nullSlug resolution state.
templatesDocyrusHtmlTemplateSummary[]Templates for the data source.
isLoadingTemplates / templatesErrorboolean / Error | nullTemplates state.
refetchTemplates() => Promise<unknown>Invalidate and reload the templates.
selectedTemplateId / setSelectedTemplateId / selectedTemplate—Selection. Changing it resets the PDF result.
templateDetailDocyrusHtmlTemplateDetail | nullServer-compiled template (body, header / footer, styles).
isLoadingTemplateDetail / templateDetailErrorboolean / Error | nullPreview state.
previewHtmlstringNative: full document HTML (compiled body + template CSS + A4 preview CSS) for a WebView.
generatePdf() => Promise<DocyrusRecordPdfResult>Server-side render.
isGeneratingPdf / pdfResult / pdfUrl / pdfError—PDF state. pdfUrl is the signed url when present.
pdfFileNamestringSuggested file name (always ends in .pdf).
localPdfUristring | nullNative: local file:// URI once prepared.
isPreparingFile / fileErrorboolean / Error | nullNative: download / on-device render state.
prepareFile() => Promise<string | null>Native: download the signed url (or render with expo-print) into the cache.
sharePdf() => Promise<string | null>Native: prepare the file if needed and open the share sheet. Resolves the shared URI.
printPdf() => Promise<boolean>Native: open the print dialog. Resolves false without expo-print.
canPrintbooleanNative: whether expo-print is installed.
reset() => voidBack to the first step and clear the result.

DocyrusRecordPdfResult

FieldTypeDescription
idstringStorage record id.
pathstringGenerated file name.
fullPathstringStorage object path (not directly fetchable).
urlstringSigned, fetchable URL (when the server returns one).
filenamestringFile name alias used by some endpoints.
bucketstringStorage bucket.
sizenumberFile size in bytes.

Native differences

  • No template editing. The web templateEditable mode (Plate HtmlTemplateEditor) is web-only, so templateEditable, templateDetailEndpoint and the record / edit state (record, editedHtml, previewEditorProps, …) are not available.
  • No Email step. There is no native EmailComposer yet, so sendEmail is not supported. RecordPdfExportStep keeps 'email' for type parity, but native never produces it.
  • The preview is a WebView (previewHtml) instead of the HTML Template Editor preview tab.
  • Native adds onShare, enablePrint, bodyHeight: number and the local-file API (prepareFile, sharePdf, printPdf, localPdfUri, canPrint). File writing and sharing use the internal lib/native-export helpers.

Translation keys

ui.recordPdfExport.*: stepSelect, stepPreview, stepPdf, stepEmail, chooseTemplate, reload, loadingTemplates, noTemplates, default, loadingPreview, webviewMissing, retry, generatingPdf, pdfGenerated, pdfOpenHint, pdfNoUrl, pdfEmpty, back, next, print, share, done.

Components

ComponentDescription
DocyrusRecordPdfExportWizardThe three-step wizard.

Type Exports

TypeDescription
DocyrusRecordPdfExportWizardPropsWizard props.
UseDocyrusRecordPdfExportOptionsHook options.
UseDocyrusRecordPdfExportResultHook result.
RecordPdfExportStep'select' | 'preview' | 'pdf' | 'email'.
DocyrusHtmlTemplateSummaryTemplate list row.
DocyrusHtmlTemplateDetailTemplate with compiled body, header / footer and styles.
DocyrusRecordPdfResultPDF render result.

RECORD_PDF_EXPORT_STEPS (['select', 'preview', 'pdf']) is exported as a value.

On this page