Aspose.PDF FOSS for TypeScript Features

Aspose.PDF FOSS for TypeScript Features

Aspose.PDF FOSS for TypeScript Features

This page surveys the major capability areas of Aspose.PDF FOSS for TypeScript and the classes that act as their entry points, so you can find the right developer-guide page for the task at hand. Each area is covered in depth on its own page.


Document and Page Management

Document is the entry point for every operation: Document.New() starts a blank document at a given PageFormat, and Document.OpenFile() / Document.Open() load an existing one from a file path or in-memory bytes. doc.Pages is an array of Page objects, and Document.WriteTo() / Document.Save() write the result back out.

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

const doc = Document.New(PageFormat.A4);
doc.Pages[0].AddText('Hello from Aspose.PDF FOSS!', 72, 720, { fontSize: 14 });
doc.WriteTo('hello.pdf');

See Core API for document lifecycle, splitting, merging, and page assembly.


Format Conversion

Document.ToHtml(), Document.ToDocx(), and Document.ToMarkdown() render every page of a document to another format; the same methods exist on Page to render a single page, plus Page.ToImage() for PNG raster output and Page.ToSvg() for standalone SVG.

const doc = Document.OpenFile('report.pdf');
const html = doc.ToHtml();                       // standalone HTML, all pages
const png = doc.Pages[0].ToImage({ scale: 2 });   // PNG bytes for page 1

See Conversion for the full set of export formats and options.


Annotations

Page.AddHighlight() and its sibling Page.Add*() methods create markup and shape annotations; each returns a live Annotation handle. Annotation.Flatten() bakes an annotation’s appearance directly into the page’s content stream and removes it from /Annots, making it permanent and non-interactive.

const highlight = doc.Pages[0].AddHighlight({ quadPoints: [72, 700, 200, 700, 72, 685, 200, 685] });
highlight.Flatten();

See Annotations for the full set of annotation types and searching annotation text.


Forms and Field Flattening

AcroForm fields are created through doc.Form, a Form facade, or directly on a Page with Page.AddTextField() / Page.AddCheckbox(). Form.AddTextField() and Form.AddCheckbox() return a field handle whose own Flatten() method bakes it into static content the same way Annotation.Flatten() does.

const field = doc.Form.AddTextField({
  page: 0, rect: [72, 660, 300, 680], name: 'FullName', value: 'Jane Doe',
});
field.Flatten();

See Forms for the full set of field types.


Security

Document.OpenFile() and Document.Open() accept a password option to open protected documents, and Document.Save() accepts an encrypt option to protect one on save. Document.Sign() and Document.Certify() add digital signatures, and Document.VerifySignatures() checks every signature already in a document.

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

try {
  const doc = Document.OpenFile('secret.pdf', { password: 'hunter2' });
  doc.WriteTo('decrypted.pdf');
} catch (e) {
  if (e instanceof InvalidPasswordError) console.error('wrong password');
  else throw e;
}

See Security for encryption, signing, and signature verification.


Redaction

Page.AddRedact() marks a rectangular region for redaction without changing the page yet; Page.ApplyRedactions() then destructively rewrites the content stream, removing the marked content for good and returning the number of redactions applied.

page.AddRedact({ rect: [220, 550, 460, 566], fill: [0, 0, 0], overlayText: '[REDACTED]' });
const applied = page.ApplyRedactions();

See Redaction for mark-mode vs. applied redactions in more detail.


Document Structure and Accessibility

Document.AutoTag() infers and authors a /StructTreeRoot from page layout — headings by font-size clustering, paragraphs, and (with opts.alt) figures — and returns an AutoTagReport. Document.GetStructTree() reads back the resulting structure tree, and Document.ValidatePdfUa() checks the document against a machine-checkable subset of PDF/UA-1.

const report = doc.AutoTag({ lang: 'en-US', title: 'Quarterly Report', tables: true });
console.log(report);

See Structure for outlines, tagging, and named destinations.


Tips and Best Practices

  • Modify the Page objects reached through doc.Pages directly — an annotation, field, or page held in a separate variable that was not obtained from the live document is not reflected when you call Save() / WriteTo().
  • Flatten() is available on both Annotation and form field handles (TextField, CheckboxField, and the other field types) — call it once interactive content should become permanent, non-editable page content.
  • Call Page.ApplyRedactions() only after every Page.AddRedact() mark for that page has been added; marks added after the call stay unapplied.
  • Catch InvalidPasswordError specifically before a broader catch-all when calling Document.OpenFile() / Document.Open() on untrusted input.
  • Document.AutoTag() produces a heuristic structure tree — always spot check the result with Document.GetStructTree() or ValidatePdfUa() rather than assuming full accessibility compliance.

Common Issues

IssueCauseFix
Document.OpenFile() / Document.Open() throws InvalidPasswordErrorThe document is password-protected and no password, or the wrong one, was suppliedPass { password: '...' } to Document.OpenFile() / Document.Open()
Redaction mark has no effectPage.ApplyRedactions() was never called, or was called before the mark was addedCall Page.AddRedact() for every mark first, then Page.ApplyRedactions() once
Flattened field or annotation still shows as interactiveFlatten() was called on a copy rather than the handle returned by the Add*() callCall Flatten() on the object returned directly by AddTextField() / AddHighlight() / etc.
ValidatePdfUa() still reports missing structure after AutoTag()AutoTag() is heuristic and may not tag every figure without an alt callbackPass an opts.alt function to AutoTag() to supply alt text for images

FAQ

Does Aspose.PDF FOSS for TypeScript depend on a commercial PDF engine?

No. It is released under the MIT license and its rendering, conversion, and signing logic runs entirely in TypeScript/JavaScript.

Can I convert a PDF straight to HTML, Markdown, or DOCX?

Yes — Document.ToHtml(), Document.ToMarkdown(), and Document.ToDocx() render every page of the document; the equivalent Page.ToHtml() / Page.ToMarkdown() / Page.ToDocx() methods render a single page.

What is the difference between marking and applying a redaction?

Page.AddRedact() only marks a region — the underlying content is still present and copy-selectable until Page.ApplyRedactions() is called, which destructively removes it.

How do I make an annotation or form field permanent and non-editable?

Call Flatten() on the object returned by the Add*() call that created it — Annotation.Flatten() for annotations, or the field handle’s own Flatten() for AcroForm fields.

Where do I go next?

Getting Started covers installation and a first working example. This developer guide continues with dedicated pages for each capability area linked above.


API Reference Summary

Class/MethodDescription
DocumentEntry point — create, load, save, and manage a PDF
Document.New() / Document.OpenFile() / Document.Open()Start a blank document, or load one from a file path or in-memory bytes
Document.WriteTo() / Document.Save()Write the document to a file path or return bytes
Document.ToHtml() / Document.ToDocx() / Document.ToMarkdown()Render every page to another format
Page.ToImage() / Page.ToSvg()Render a single page to PNG or SVG
Page.AddHighlight() and other Page.Add*() annotation methodsCreate an annotation, returning a live handle
Annotation.Flatten()Bake an annotation’s appearance into static page content
Form / Form.AddTextField() / Form.AddCheckbox()AcroForm facade and field creation
Document.Sign() / Document.Certify() / Document.VerifySignatures()Add or verify digital signatures
Page.AddRedact() / Page.ApplyRedactions()Mark and apply content redaction
Document.AutoTag() / Document.GetStructTree()Author and read the document’s logical structure tree

See Also