I/O hoạt động

I/O mô hình

Aspose.PDF FOSS for Java consistently accepts both file paths and Java streams as nhập và xuất trong tất cả các APIs lớn, bao gồm: Document, PdfFileEditor,Và tất cả Phân loại facade.

Tài liệu I/O

Các Document lớp chấp nhận một file path string hoặc một InputStream trong nhà xây dựng của nó. Các save() phương pháp chấp nhận một file path string hoặc một 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);
}

Cả hai nhà xây dựng tải toàn bộ tài liệu vào trí nhớ. Đối với các tài khoản lớn, đảm bảo đủ không gian hoặc xem xét sử dụng PdfFileEditor.setUseDiskBuffer(true).

PDFFileEditor Stream Hỗ trợ

PdfFileEditor hoạt động chấp nhận cả file path string và Java InputStream/OutputStream Các đối tượng:

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

In-Memory Động cơ

Đối với các ống lưu trữ trong bộ nhớ mà tránh tệp tạm thời, sử dụng ByteArrayOutputStream để thu thập tài liệu xuất, sau đó vẽ với ByteArrayInputStream Đối với xử lý downstream:

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

Phân tích I/O

Tất cả các lớp học (ví dụ:. PdfAnnotationEditor, PdfContentEditor, PdfFileSecurity) theo cùng một mô hình nối-hành động-save và chấp nhận các đường file, dòng hoặc một Document Đối tượng qua các bindPdf() Phương pháp .

See Also

 Tiếng Việt