I/O 작업

I/O 패턴

Aspose.PDF FOSS for Java은 모든 주요 API에서 파일 경로와 Java 스트림을 입력 및 출력으로 일관되게 허용합니다. 여기에는 Document, PdfFileEditor 및 모든 파사드 클래스가 포함됩니다.

문서 I/O

Document 클래스는 생성자에서 파일 경로 문자열이나 InputStream을(를) 허용합니다. save() 메서드는 파일 경로 문자열이나 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 스트림 지원

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

인메모리 파이프라인

임시 파일을 사용하지 않는 인메모리 파이프라인의 경우, 문서 출력을 캡처하기 위해 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);

Facade I/O

모든 파사드 클래스(예: PdfAnnotationEditor, PdfContentEditor, PdfFileSecurity)는 동일한 bind-operate-save 패턴을 따르며, 파일 경로, 스트림 또는 Document 객체를 bindPdf() 메서드를 통해 받아들입니다.

참조

 한국어