Java で PDF アーティファクトをカウントする
Contents
[
Hide
]
ページ上のページネーションアーティファクトをカウントする
ページ上の主要なページネーションアーティファクトサブタイプの迅速なカウントが必要なときは、この例を使用してください。
- Document で元の PDF を開いてください。
- 対象ページ Page の Artifact コレクションを読み取ってください。
- ページの 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);
}
}