Aspose.PDF FOSS for TypeScript เป็นไลบรารีโอเพ่นซอร์สสำหรับการสร้าง, แก้ไข, แปลง, และทำให้เอกสาร PDF มีความปลอดภัยในแอปพลิเคชัน Node.js (>=22) applications. คลาส Document และ Page เป็นจุดเข้าสำคัญ: Document.OpenFile() / Document.Open() โหลดไฟล์ที่มีอยู่หรือไบต์ในหน่วยความจำ, Document.New() เริ่มต้นเอกสารเปล่า, และ WriteTo() / Save() เขียนผลลัพธ์ออกไป, โดยอาจใช้การบีบอัด xref-stream. โครงการนี้เป็นแพ็กเกจที่ไม่มีการพึ่งพาใด ๆ (Node.js เป็นความต้องการของรันไทม์เพียงอย่างเดียว) และกำลังอยู่ในระยะพัฒนาต้นแบบอย่างแข็งขัน (เวอร์ชันปัจจุบัน 0.1.0).
นอกเหนือจากการแก้ไขเอกสารและหน้าหลัก — การแยก, การรวม, การสกัด, การจัดเรียงใหม่, และการต่อหน้าด้วย Document.Split(), Document.Merge(), Document.ExtractPages(), และ Document.Append() — ไลบรารีนี้สามารถแปลงหน้าและเอกสารทั้งหมดเป็นรูปแบบอื่น ๆ ด้วย ToHtml(), ToMarkdown(), ToDocx(), ToSvg(), ToImage(), และ ToEpub(). การสนับสนุนการทำโน้ตอธิบายครอบคลุมการไฮไลท์, การขีดเส้นใต้, การทำเส้นขยุกขยิก, การขีดฆ่า, ลิงก์, หมายเหตุข้อความ, ข้อความอิสระ, และสแตมป์ผ่านเมธอดเช่น Page.AddHighlight() และ Page.AddStamp(). ฟิลด์ AcroForm (ข้อความ, เช็คบ็อกซ์, เรดิโอ, คอมโบบ็อกซ์, ลิสต์บ็อกซ์, และปุ่มกด) สร้างด้วยคลาส Form และซับคลาส Field ที่กำหนดประเภท, และเอกสารสามารถเข้ารหัสด้วย AES-128, AES-256, หรือ RC4, เซ็นดิจิทัลด้วย Document.Sign(), และทำการลบข้อมูลด้วย Document.Redact() / Page.ApplyRedactions().
Aspose.PDF FOSS for TypeScript ถูกเผยแพร่ภายใต้สัญญาอนุญาต MIT โดยไม่มีค่าธรรมเนียมการรันไทม์หรือข้อจำกัดการใช้งาน (ดูส่วนการติดตั้งด้านล่าง). สำหรับตระกูลผลิตภัณฑ์ระดับองค์กร, ดู Aspose.PDF — Enterprise Product Family.
Document.OpenFile() / Document.Open(), หรือเริ่มต้นเป็นไฟล์เปล่าด้วย Document.New()Document.Split(), Document.Merge(), Document.ExtractPages(), Document.Reorder(), และ Document.Append()Document.SetMetadata() / Document.GetMetadata()Document.WriteTo(), โดยอาจบีบอัดเพิ่มเติมผ่าน xref streams และ object streamsDocument.ToHtml() และเป็น GitHub-flavored Markdown ด้วย Document.ToMarkdown().docx แบบ reflowable หรือ fixed-layout ด้วย Document.ToDocx() / Page.ToDocx()Page.ToSvg() หรือเป็นไบต์ PNG/TIFF แบบราสเตอร์ด้วย Page.ToImage()Document.ToEpub() สำหรับการจัดจำหน่ายบนอีรีดเดอร์Page.AddHighlight(), Page.AddUnderline(), Page.AddSquiggly(), และ Page.AddStrikeOut()Page.AddTextNote() และ Page.AddFreeText()Page.AddStamp() และลิงก์ที่คลิกได้ด้วย Page.AddLink()Annotation.Flatten() ที่เปิดให้ใช้บนชนิดย่อยที่กำหนดเช่น MarkupAnnotation และ StampAnnotationForm (AddTextField(), AddCheckbox(), AddRadioGroup(), AddComboBox(), AddListBox(), AddPushButton())SetStyle() และ GenerateAppearance() บนคลาสฟิลด์ที่กำหนดประเภท เช่น TextField, ChoiceField, และ ButtonFieldSetActions() บน Field ใด ๆDocument.FlattenForm()encrypt ของ Document.WriteTo() พร้อม Permissions ที่ละเอียดDocument.Sign() และตรวจสอบลายเซ็นด้วย Document.VerifySignatures()Document.AddDocumentTimestamp()Document.Redact(), Document.RedactText() และ Page.ApplyRedactions()เปิดไฟล์ PDF และแปลงออกเป็นหลายรูปแบบ downstream ในหนึ่งขั้นตอน.
git clone https://github.com/aspose-pdf-foss/Aspose.PDF-FOSS-for-TypeScript.git
cd Aspose.PDF-FOSS-for-TypeScript
npm install
npm run buildimport { Document } from '@asposefoss/pdf';
const doc = Document.OpenFile('in.pdf');
const svg = doc.Pages[0].ToSvg(); // standalone <svg> string
// fs.writeFileSync('page1.svg', svg);
const png = doc.Pages[0].ToImage({ scale: 2 }); // Uint8Array of PNG bytes @144 DPI
// fs.writeFileSync('page1.png', png);
const html = doc.ToHtml(); // standalone semantic HTML, all pages
// fs.writeFileSync('out.html', html);
const md = doc.ToMarkdown(); // GFM Markdown, all pages
// fs.writeFileSync('out.md', md);
const docx = doc.ToDocx(); // .docx bytes, reflowed, images in the package
// fs.writeFileSync('out.docx', docx);
const fixed = doc.ToDocx({ mode: 'textbox' }); // .docx keeping each page's own geometry
// fs.writeFileSync('fixed.docx', fixed);
โหลด PDF, แก้ไขหน้าของมันและเมตาดาต้า, แล้วบันทึกออกพร้อมการบีบอัด.
import { Document } from '@asposefoss/pdf';
// Open from disk (or Document.Open(uint8array) for in-memory data)
const doc = Document.OpenFile('input.pdf');
// Inspect and edit pages
console.log(doc.Pages.length);
doc.Pages[0].Rotate = 90;
doc.RemovePage(2); // 1-based page number
doc.Reorder([3, 1, 2]);
// Metadata
doc.SetMetadata({ title: 'Report', author: 'Jane', custom: { Dept: 'R&D' } });
// Save
doc.WriteTo('output.pdf'); // or: const bytes = doc.Save();
doc.WriteTo('small.pdf', { compressed: true }); // xref stream + object streams
เริ่มต้นด้วยเอกสารเปล่า, เพิ่มข้อความที่กำหนดตำแหน่ง, และต่อหน้าเพิ่มอีกหนึ่งหน้า.
import { Document, PageFormat } from '@asposefoss/pdf';
const doc = Document.New(PageFormat.A4); // one blank A4 page
doc.Pages[0].AddText('Hello', 72, 720, { fontSize: 14 });
doc.AddPage(PageFormat.A4.landscape()); // append more as you go
doc.WriteTo('scratch.pdf');
เข้ารหัส PDF ที่มีอยู่ด้วยคู่รหัสผ่านผู้ใช้/เจ้าของและ AES-256 โดยจำกัดการคัดลอกและการแก้ไข.
import { Document } from '@asposefoss/pdf';
const doc = Document.OpenFile('in.pdf');
doc.WriteTo('locked.pdf', {
encrypt: {
userPassword: 'open-me', // required to open (default '')
ownerPassword: 'full-rights', // default: same as userPassword
algorithm: 'aes256', // 'aes256' (default) | 'aes128' | 'rc4'
permissions: { copying: false, modifying: false },
encryptMetadata: true,
},
});
Aspose.PDF FOSS for TypeScript ถูกเผยแพร่ภายใต้สัญญาอนุญาต MIT, อนุญาตให้ใช้ได้ฟรีในผลิตภัณฑ์เชิงพาณิชย์โดยไม่มีค่าธรรมเนียมการรันไทม์. โค้ดต้นฉบับสามารถเข้าถึงได้สาธารณะบน GitHub.
แพคเกจนี้รองรับ Node.js 22 ขึ้นไปและไม่มีการพึ่งพา runtime อื่นใด ดูส่วนการติดตั้งข้างบนสำหรับคำสั่งติดตั้งปัจจุบัน.
ไลบรารีนี้อ่านและเขียน PDF, Markdown, SVG, และ TIFF, และสามารถสร้างผลลัพธ์ในรูปแบบ DOCX, HTML, PNG, และ EPUB ได้.
ใช้ Document.New(PageFormat.A4) เพื่อสร้างเอกสารเปล่า แล้วเพิ่มหน้าและบันทึกด้วย Document.WriteTo() .
ไม่จำเป็นต้องมีคีย์ใบอนุญาตหรือขั้นตอนการเปิดใช้งาน ไลบรารีทำงานโดยไม่มีใบอนุญาตเต็มรูปแบบโดยไม่มีค่าใช้จ่ายภายใต้ MIT License.