调整 PDF 页面内容

调整 PDF 页面内容

Java 示例调整第 1 页和第 3 页的内容区域,并检查布尔返回值。

步骤

  1. 创建一个 PdfFileEditor 实例。
  2. 选择要调整其内容大小的页面。
  3. 调用 resizeContents 使用目标宽度和高度。
  4. 检查返回值,并在继续之前处理失败情况。
  5. 保存已更新的文档。

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.");
    }
}