מקרי שימוש

מקרי שימוש

מדריך זה מציג מקרי שימוש מהעולם האמיתי עבור Aspose.PDF FOSS עבור TypeScript, כולל יצירת מסמכים, זרימות עבודה של סקירה, סינון, הפצה בטוחה, איסוף נתונים בטפסים, ופרסום אינטרנט מתויג. הוא דורש Node.js 22 או גרסה מאוחרת יותר.

יצירת מסמכים והרכבת דפים

בנה קובץ PDF מאפס על-ידי פתיחת Document ריק ב-PageFormat נתון, הצבת טקסט באמצעות Page.AddText(), והוספת דפים נוספים. תבנית זו משמשת לבסיס יצירת חשבוניות, הדפסת תעודות, וצינורות ייצור דוחות:

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');

סינון נתונים רגישים לפני הפצה

סמן ולאחר מכן הסר באופן הרסני שדות רגישים — מזהה עובד, מספר חשבון בנק — לפני שהמסמך יוצא מהארגון:

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');

ראה גם

 עברית