Use Cases

This guide demonstrates real-world use cases for Aspose.PDF FOSS for TypeScript, spanning document generation, review workflows, redaction, secure distribution, form-based data collection, and tagged web publishing. It requires Node.js 22 or later.

Document Generation and Page Assembly

Build a PDF from scratch by starting a blank Document at a given PageFormat, placing text with Page.AddText(), and appending further pages. This pattern underlies invoice generation, certificate printing, and report production pipelines:

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

const doc = Document.New(PageFormat.A4); // one blank A4 page
doc.Pages[0].AddText('Monthly Report', 72, 720, { fontSize: 14 });
doc.AddPage(PageFormat.A4.landscape()); // append more as you go
doc.WriteTo('report.pdf');

Reviewing and Redlining with Annotations

Mark up a shared draft with highlights, sticky notes, and free-text comments, then bake the review into a final, non-editable page once it is approved:

const draft = Document.OpenFile('draft.pdf');
const page = draft.Pages[0];

page.AddHighlight({ quads: [72, 700, 300, 700, 72, 685, 300, 685], color: [1, 1, 0] });
const note = page.AddFreeText({
  rect: [320, 685, 500, 715],
  contents: 'Please confirm this figure before publishing.',
  fontSize: 10,
});

// Once the review is resolved, bake the comment into static content:
note.Flatten();
draft.WriteTo('reviewed.pdf');

Redacting Sensitive Data Before Distribution

Mark and then destructively remove sensitive fields — an employee ID, a bank account number — before a document leaves an organization:

const memo = Document.OpenFile('internal-memo.pdf');
const page2 = memo.Pages[0];

page2.AddRedact({
  rect: [220, 548, 460, 566],
  fill: [0, 0, 0],
  overlayText: '[REDACTED]',
  align: 'center',
  fontSize: 9,
  textColor: [1, 1, 1],
});
page2.ApplyRedactions(); // destructive — the covered content is gone
memo.WriteTo('memo-for-distribution.pdf');

Securing and Signing Documents for Distribution

Certify a finished document, then encrypt it to a specific recipient’s certificate so only that recipient can open it:

async function secureAndDistribute(sourcePath: string): Promise<void> {
  const doc = Document.OpenFile(sourcePath);
  await doc.Certify(
    { certificate: authorCert, privateKey: authorKey },
    { permissions: 'form-fill', reason: 'Certifying the final report' },
  );

  const encryptedBytes = doc.Save({
    encrypt: {
      recipients: [{ certificate: recipientCertPem }],
      algorithm: 'aes256',
      permissions: { copying: false },
    },
  });
  writeFileSync('report-secure.pdf', encryptedBytes);
}

Collecting Structured Data with Fillable Forms

Build a fillable intake form, then read the submitted values back out of a returned copy — useful for processing filled application forms without a separate form-submission server:

const template = Document.New(PageFormat.A4);
const form = template.Form;
const pageNum = template.Pages[0].Number;

form.AddTextField({ page: pageNum, rect: [200, 670, 450, 690], name: 'FullName' });
form.AddCheckbox({ page: pageNum, rect: [200, 630, 218, 648], name: 'Subscribe' });
template.WriteTo('intake-form.pdf');

// Later, after the form comes back filled in:
const submitted = Document.OpenFile('intake-form-filled.pdf');
for (const field of submitted.Form.Fields) {
  console.log(field.FullName, '=', field.Value);
}

Publishing Tagged, Web-Ready Documents

Tag a document’s logical structure, then export it to semantic HTML that reflows correctly for web readers — the export walks the same structure tree the tagging pass builds:

const source = Document.OpenFile('report.pdf');
const report = source.AutoTag({ title: true });
console.log(`tagged: ${report.headings} heading(s), ${report.paragraphs} paragraph(s)`);

const html = source.ToHtml(); // reflowable markup, built from the structure tree
writeFileSync('report.html', html, 'utf8');

See Also