Introduction

The introductory post shows the basic shape of conversion: Document.ToHtml(), Document.ToMarkdown(), and Document.ToDocx(), each called with no arguments to get a reasonable default. Every one of those methods takes an options object that changes what actually comes out — semantic markup versus a pixel-faithful copy, a reflowable Word document versus one that reproduces each page’s exact layout.

This post covers those options, plus a conversion direction the introduction does not touch at all: validating a document against the PDF/A, PDF/X, and PDF/UA standards and remediating it toward compliance with Document.ConvertToPdfA() and its siblings.


What’s Included

HTML Export: Semantic vs Fixed

Document.ToHtml() called with no options walks the document’s structure tree and emits reflowable markup — headings and paragraphs that read naturally in a browser at any width. That mode depends on the document being tagged first (Document.CreateStructTree() or an equivalent tagging pass); without a structure tree, the export falls back to a plain heuristic body instead of true semantic markup. Passing { mode: 'fixed', fonts: 'embed' } switches to a different rendering strategy entirely: each page becomes positioned SVG and absolutely-placed text, with every embeddable font program inlined as a base64 WOFF @font-face so the page looks the same without the reader having the fonts installed.

// Semantic mode reflows from the structure tree, so this must run after the
// tagging pass: ToHtml falls back to a heuristic body when GetStructTree() is
// null, and the export loses its heading structure silently.
const semantic = doc.ToHtml();
const fixed = doc.ToHtml({ mode: 'fixed', fonts: 'embed' });

The two outputs serve different purposes: semantic HTML is what you want for reading or re-publishing content on the web, and fixed HTML is what you want when the page’s exact visual layout has to survive unmodified in a browser.

Word and Vector Exports

Document.ToDocx() called with no options produces a reflowed .docx: paragraphs and images that a word processor can rewrap and edit like a normal document. Passing { mode: 'textbox' } instead keeps each page’s own geometry, placing content in fixed text boxes rather than letting it reflow — closer to a faithful visual copy than an editable document. Page.ToSvg() renders a single page to a standalone <svg> string, useful when a vector, resolution-independent copy of one page is needed rather than a raster image.

import { Document } from '@asposefoss/pdf';

const doc = Document.OpenFile('in.pdf');
const svg = doc.Pages[0].ToSvg();               // standalone <svg> string
const docx = doc.ToDocx();                       // .docx bytes, reflowed, images in the package
const fixed = doc.ToDocx({ mode: 'textbox' });   // .docx keeping each page's own geometry

Validating and Converting to PDF/A, PDF/X, and PDF/UA

Document.ValidatePdfA(), Document.ValidatePdfX(), and Document.ValidatePdfUa() each check the document against a curated, machine-checkable subset of the corresponding standard — PDF/A (ISO 19005) for long-term archival, PDF/X (ISO 15930) for print production, and PDF/UA (ISO 14289-1) for accessibility — and return a ValidationReport with a Passed flag summarizing the result. Document.ConvertToPdfA() (and the equivalent ConvertToPdfX()/ConvertToPdfUa()) attempts to remediate the document toward that level, then re-validates, returning a ConversionReport that lists which actions it actually applied and which issues remain unresolved.

import { Document } from '@asposefoss/pdf';

const doc = Document.OpenFile('in.pdf');
const pdfa = doc.ValidatePdfA('2b');
console.log(`validate: PDF/A-2b ${pdfa.Passed ? 'passes' : 'fails'}`);

// Conversion runs against a copy: the live document is still saved
// unconverted, so ConvertToPdfA must never touch it directly.
const pages = doc.Pages;
const allPages: number[] = [];
for (let i = 1; i <= pages.length; i++) allPages.push(i);
const copy = doc.ExtractPages(allPages);
const conversion = copy.ConvertToPdfA('2b');

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

Conversion is not guaranteed to reach full compliance in one pass — common causes of a remaining failure include non-embedded fonts and a missing output intent, both of which show up in conversion.unresolved.


Quick Start

Install the package, then render one page to SVG and the whole document to reflowed HTML and DOCX:

asposefoss/pdf is not yet published — build from source until it ships. See the project README for build instructions.
import { Document } from '@asposefoss/pdf';

const doc = Document.OpenFile('in.pdf');

const svg = doc.Pages[0].ToSvg();   // standalone <svg> string
const html = doc.ToHtml();          // reflowable HTML (falls back without a structure tree)
const docx = doc.ToDocx();          // .docx bytes, reflowed, images in the package

// fs.writeFileSync('page1.svg', svg);
// fs.writeFileSync('out.html', html);
// fs.writeFileSync('out.docx', docx);

Supported Formats

FormatExtensionReadWrite
PDFpdf
Markdownmd
SVGsvg
TIFFtiff
DOCXdocx
HTMLhtml
PNGpng
EPUBepub

Open Source & Licensing

Aspose.PDF FOSS for TypeScript is released under the MIT license, with source published on GitHub. There is no evaluation watermark, usage limit, or separate license file to manage, and the library may be used in commercial products without royalties.

The package is currently at version 0.1.0, reflecting active early-stage development. Node.js (>=22) is the only runtime requirement, and the package has no other third-party dependencies.


Getting Started