การดําเนินงาน I/O
รูปแบบการเข้า/ออก
Aspose.PDF FOSS for Java consistently accepts both file paths and Java streams as การเข้าและการออกใน APIs ทั้งหมดรวมถึง Document, PdfFileEditor,และทุกๆอย่าง ช่วงเรียนด้านหน้า.
เอกสาร I/O
การ Document class ยอมรับร่องทางไฟล์หรือการใช้งาน InputStream ในตัวสร้างของมัน. การ save() วิธีการรับสายทางไฟล์หรือเส้นที่ใช้ในการเขียน File Path OutputStream.
// File path input
try (Document doc = new Document("input.pdf")) {
doc.save("output.pdf");
}
// Stream input/output
try (Document doc = new Document(inputStream)) {
doc.save(outputStream);
}ทั้งสองคอนสตรั๊กเตอร์จะโหลดเอกสารทั้งหมดเข้าในความจํา. สําหรับเภทเติมขนาดใหญ่, ให้แน่ใจว่า พื้นที่เก็บของพอเพียง หรือพิจารณาใช้ PdfFileEditor.setUseDiskBuffer(true).
การสนับสนุน PdfFileEditor Stream
PdfFileEditor การปฏิบัติการรับทั้งสายเส้นทางไฟล์และ Java InputStream/OutputStream อัตถุประกอบ:
PdfFileEditor editor = new PdfFileEditor();
// All operations support both file paths and streams
editor.concatenate(new InputStream[]{s1, s2}, outputStream);
editor.extract(inputStream, 1, 3, outputStream);ช่องทางในความจํา
สําหรับ pipelines ในความจําที่หลีกเลี่ยงไฟล์ชั่วคราว, ใช้ ByteArrayOutputStream ไปยัง การจับผลิตเอกสาร แล้วพับด้วย ByteArrayInputStream สําหรับการประมวลผลด้านล่าง:
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
try (Document doc = new Document()) {
doc.getPages().add();
doc.save(buffer);
}
byte[] pdfBytes = buffer.toByteArray();
// Pass pdfBytes downstream — no temp file needed
ByteArrayInputStream next = new ByteArrayInputStream(pdfBytes);การเข้าออกของหน้าตึก
ทุกประเภทของหน้าตึก (เช่น. PdfAnnotationEditor, PdfContentEditor, PdfFileSecurity) ตามแบบผูก-ดําเนินการ-บันทึกเดียวกันและยอมรับเส้นทางไฟล์, ธารสารหรือ a Document อัตราทางการใช้งานของพวกเขา bindPdf() วิธีการ.