调整 PDF 页面内容
Contents
[
Hide
]
调整 PDF 页面内容
Java 示例调整第 1 页和第 3 页的内容区域,并检查布尔返回值。
步骤
- 创建一个
PdfFileEditor实例。 - 选择要调整其内容大小的页面。
- 调用
resizeContents使用目标宽度和高度。 - 检查返回值,并在继续之前处理失败情况。
- 保存已更新的文档。
Java 示例
public static void resizePdfPageContents(Path inputFile, Path outputFile) {
PdfFileEditor pdfEditor = new PdfFileEditor();
if (!pdfEditor.resizeContents(inputFile.toString(), outputFile.toString(), new int[] {1, 3}, 400, 750)) {
throw new IllegalStateException("Failed to resize PDF page contents.");
}
}