사용 사례
이 가이드는 Aspose.PDF FOSS for TypeScript의 실제 사용 사례를 보여주며, 문서 생성, 검토 워크플로, 민감 정보 삭제, 안전한 배포, 양식 기반 데이터 수집 및 태그가 지정된 웹 게시를 포괄합니다. Node.js 22 이상이 필요합니다.
문서 생성 및 페이지 조립
주어진 PageFormat에서 빈 Document을 시작하고, Page.AddText()로 텍스트를 배치한 뒤 추가 페이지를 붙여 PDF를 처음부터 구축합니다. 이 패턴은 인보이스 생성, 인증서 인쇄 및 보고서 생산 파이프라인의 기반이 됩니다:
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');주석을 통한 검토 및 레드라이닝
공유 초안을 하이라이트, 스티키 노트, 자유 텍스트 주석으로 표시한 다음, 승인되면 검토 내용을 최종 비편집 가능한 페이지로 고정합니다:
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');배포 전 민감 데이터 삭제
문서가 조직을 떠나기 전에 민감한 필드(예: 직원 ID, 은행 계좌 번호)를 표시한 뒤 파괴적으로 제거합니다:
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');배포용 문서 보안 및 서명
완성된 문서를 인증한 후 특정 수신자의 인증서로 암호화하여 해당 수신자만 열 수 있도록 합니다:
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);
}작성 가능한 양식을 사용한 구조화된 데이터 수집
작성 가능한 접수 양식을 만든 뒤, 반환된 사본에서 제출된 값을 다시 읽어옵니다 — 별도의 양식 제출 서버 없이 작성된 신청서를 처리하는 데 유용합니다:
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);
}태그가 지정된 웹 준비 문서 게시
문서의 논리 구조에 태그를 지정한 뒤, 웹 리더에 맞게 올바르게 재배치되는 의미론적 HTML로 내보냅니다 — 내보내기는 태깅 단계가 만든 동일한 구조 트리를 따라갑니다:
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');