Quickstart

Quickstart

This page walks through the smallest useful cycle: create a new PDF, place text on it, add a second page, save it to disk, and reopen the result to confirm the page count and content survived the round trip.


Prerequisites

RequirementDetail
Node.js22 or later
Package@asposefoss/pdf installed (Installation)

1. Create a document and add text

Document.New() takes a PageFormat and starts a document with one blank page in that size. doc.Pages[0] is the first Page; Page.AddText() places positioned text on it, and Document.AddPage() appends further pages — here a landscape variant of the same format.

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.AddPage(PageFormat.A4.landscape());

console.log('Page count:', doc.Pages.length);

2. Save the document

Call Document.WriteTo() on the doc object built in step 1 to write it to a file path — this is the same save call used throughout the developer guide, and by default it produces a PDF with no additional compression options.

doc.WriteTo('quickstart.pdf');

3. Reopen and verify

Document.OpenFile() reads the quickstart.pdf file written in step 2 back from disk into a new Document instance. Reading Pages.length on that reopened document confirms both pages — the original A4 page and the landscape page appended with AddPage() — were written correctly.

const reopened = Document.OpenFile('quickstart.pdf');
console.log('Reloaded page count:', reopened.Pages.length); // 2

Next Steps

See Also