Conversion

Conversion

This page covers rendering a PDF to other formats and converting a document toward PDF/A compliance. Document exposes one To*() method per output format for the whole document; the same methods exist on Page to render a single page.


Rendering to Other Document Formats

Document.ToHtml(), Document.ToDocx(), and Document.ToMarkdown() render every page; Page.ToSvg() and Page.ToImage() render one page to a standalone SVG string or PNG bytes. Each accepts its own options — mode on DocxOptions (‘flow’ reflows content, ’textbox’ keeps each page’s own geometry) and images on MarkdownExportOptions (‘inline’ embeds image data URIs, ’external’ writes separate files into imageDir).

const doc = Document.OpenFile('in.pdf');
const svg = doc.Pages[0].ToSvg();               // standalone <svg> string
const png = doc.Pages[0].ToImage({ scale: 2 }); // Uint8Array of PNG bytes @144 DPI
const html = doc.ToHtml();                      // standalone semantic HTML, all pages
const md = doc.ToMarkdown();                    // GFM Markdown, all pages
const docx = doc.ToDocx();                      // .docx bytes, reflowed, images in the package
const fixed = doc.ToDocx({ mode: 'textbox' });  // .docx keeping each page's own geometry

ImageOptions (for Page.ToImage()) also accepts format, quality, scale, an explicit width / height, and background (‘white’ or ’transparent’).


Converting Toward PDF/A

Document.ConvertToPdfA() attempts to remediate a document toward a PDF/A level (‘b’ or ‘u’) and re-validates it, returning a ConversionReport with applied (the remediation actions it took), unresolved (issues it could not fix), and passed. Run it on a copy — for example one made with Document.ExtractPages() — so the live, working document is never altered by the conversion.

// ExtractPages gives an independent copy; ConvertToPdfA never touches the original.
const copy = doc.ExtractPages(doc.Pages.map((_, i) => i + 1));
const conversion = copy.ConvertToPdfA('2b');

console.log(`applied ${conversion.applied.length} action(s), `
  + `${conversion.unresolved.length} unresolved, `
  + `result: ${conversion.passed ? 'passes' : 'still fails'} PDF/A-2b`);
copy.WriteTo('output-pdfa.pdf');

Other Export Formats

Beyond HTML, Markdown, DOCX, SVG, and PNG, the library also exports TIFF (TiffExportOptions, encodeTiff()) and imports/exports AcroForm field values in FDF and XFDF (exportFdfFile(), exportXfdfFile(), importFdfFile(), importXfdfFile()) — useful for exchanging filled form data separately from the PDF itself.


Tips and Best Practices

  • Run Document.ConvertToPdfA() on a copy (for example from Document.ExtractPages()), never on the live document you still need to save unconverted.
  • Check ConversionReport.unresolved even when passed is true for a looser validation level — some remediation actions only fully resolve at a stricter level.
  • Use mode: 'textbox' on DocxOptions when the DOCX output needs to keep each page’s exact visual geometry; use the default 'flow' mode when it should reflow like a normal word-processing document.
  • Pass images: 'external' and an imageDir on MarkdownExportOptions for large documents, rather than the default inline data URIs, to keep the Markdown file itself small.

Common Issues

IssueCauseFix
ConvertToPdfA() still reports passed: falseNot every issue ConversionReport.unresolved lists can be auto-remediated (e.g. missing embedded fonts or a missing /OutputIntent)Address the specific unresolved rules manually, then re-run ConvertToPdfA()
Live document was unexpectedly modified after a PDF/A conversion attemptConvertToPdfA() was called directly on the working document instead of a copyCall it on a copy made with Document.ExtractPages()
Markdown export produces one huge fileThe default images: 'inline' embeds every image as a data URIPass { images: 'external', imageDir: '...' } to write images as separate files
DOCX output loses the original page layoutThe default mode: 'flow' reflows content like a word processorPass { mode: 'textbox' } to keep each page’s own geometry

FAQ

Which formats can a PDF be converted to?

HTML, Markdown, and DOCX for the whole document (Document.ToHtml() / ToMarkdown() / ToDocx()); SVG and PNG per page (Page.ToSvg() / Page.ToImage()); plus TIFF and FDF/XFDF form-data export.

Does converting to PDF/A modify my original document?

Only if you call ConvertToPdfA() on it directly. Call it on a copy — for example doc.ExtractPages(doc.Pages.map((_, i) => i + 1)) — to keep the original document unconverted.

How do I know if a PDF/A conversion actually succeeded?

Check ConversionReport.passed. applied lists what the conversion fixed, and unresolved lists what it could not — inspect unresolved even when passed is true.

Can I export just the filled-in form field values, without the PDF itself?

Yes — exportFdfFile() and exportXfdfFile() write the current AcroForm field values to a separate FDF or XFDF file; importFdfFile() / importXfdfFile() read them back into a document.


API Reference Summary

Class/MethodDescription
Document.ToHtml() / Document.ToDocx() / Document.ToMarkdown()Render every page to another document format
Page.ToSvg() / Page.ToImage()Render a single page to SVG or PNG
DocxOptions / MarkdownExportOptions / ImageOptionsPer-format rendering options
Document.ConvertToPdfA()Remediate a document toward a PDF/A level and re-validate
ConversionReportThe conversion outcome: applied, unresolved, passed
TiffExportOptions / encodeTiff()Export to TIFF
exportFdfFile() / exportXfdfFile() / importFdfFile() / importXfdfFile()Export or import AcroForm field values as FDF/XFDF

See Also