Java で PDF アーティファクトをカウントする

ページ上のページネーションアーティファクトをカウントする

ページ上の主要なページネーションアーティファクトサブタイプの迅速なカウントが必要なときは、この例を使用してください。

  1. Document で元の PDF を開いてください。
  2. 対象ページ Page の Artifact コレクションを読み取ってください。
  3. ページの Artifact コレクションを走査し、報告するページネーションのサブタイプごとにアーティファクトを数えてください。
public static void countPdfArtifacts(Path inputFile) {
    try (Document document = new Document(inputFile.toString())) {
        int watermarks = 0;
        int backgrounds = 0;
        int headers = 0;
        int footers = 0;

        for (Artifact artifact : document.getPages().get_Item(1).getArtifacts()) {
            if (artifact.getType() == Artifact.ArtifactType.Pagination) {
                if (artifact.getSubtype() == Artifact.ArtifactSubtype.Watermark) {
                    watermarks++;
                }
                if (artifact.getSubtype() == Artifact.ArtifactSubtype.Background) {
                    backgrounds++;
                }
                if (artifact.getSubtype() == Artifact.ArtifactSubtype.Header) {
                    headers++;
                }
                if (artifact.getSubtype() == Artifact.ArtifactSubtype.Footer) {
                    footers++;
                }
            }
        }

        System.out.println("Watermarks: " + watermarks);
        System.out.println("Backgrounds: " + backgrounds);
        System.out.println("Headers: " + headers);
        System.out.println("Footers: " + footers);
    }
}

関連トピック