Java を使用して PDF 内のテーブルを管理する

PDF ドキュメント内のテーブルを追加、抽出、削除します。プログラムで PDF ファイルを変更するには、Java の Aspose.PDF を使用してください。

テーブルで最も人気の高いアクション - Java

Java ライブラリを使用して PDF ドキュメント内のテーブルを管理する方法

テーブルを操作するために、Javaプラットフォーム用の機能が豊富で強力で使いやすい変換APIである Aspose.PDF for Java APIを使用します。最新バージョンを Maven から直接ダウンロードし、pom.xmlに以下の設定を追加することで、Mavenベースのプロジェクト内にインストールできます。

Repository

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java AP</name>
    <url>https://releases.aspose.com/java/repo/</url>
</repository>

Dependency

<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-pdf</artifactId>
<version>version of aspose-pdf API</version>
</dependency>

Java でテーブルをPDFに追加


ご使用の環境でコードを試すには、Aspose.PDF for Java が必要です。

  1. PDF を Document のインスタンスとともに読み込みます。
  2. インデックスを介してページにアクセスします。
  3. Table オブジェクトを作成します。
  4. テーブル設定を設定します (例:境界線の設定)。
  5. テーブルを移入します。
  6. テーブルをページに追加します。
  7. ファイルを保存します。

PDF 形式のテーブルを追加-Java

Document pdfDocument = new Document(DATA_DIR.resolve("input.pdf").toString());
com.aspose.pdf.Table table = new com.aspose.pdf.Table();

able and cell borders
BorderInfo border = new BorderInfo(BorderSide.All, 0.5f, Color.getLightGray());
table.setBorder(border);
table.setDefaultCellBorder(border);

0 rows with 3 columns each
for (int i = 1; i < 10; i++) {
    Row row = table.getRows().add();
    for (int j = 1; j <= 3; j++) {
        row.getCells().add("Column (" + i + ", " + j + ")");
    }
}

able to the first page and save the document
pdfDocument.getPages().get_Item(1).getParagraphs().add(table);
pdfDocument.save(DATA_DIR.resolve("document_with_table.pdf").toString());
pdfDocument.close();