页面元素
这本指南显示如何使用页面几何,文物装饰和嵌入式图像. 在 Aspose.PDF FOSS 中的文件附件,你将学习阅读页面尺寸 通过 getMediaBox(),列出: Artifact 管理和控制这些物体. EmbeddedFileCollection.
页面几何学
Each Page 通过盒子属性来展示其几何结构:
getMediaBox()全页边界getCropBox()可见区域getRotate()页面旋转为 (0, 90, 180 或 270) 度.
从媒体框中读取宽度和高度,以计算内容放置位置:
try (Document doc = new Document("input.pdf")) {
PageCollection pages = doc.getPages();
Page page = pages.get(1);
double width = page.getMediaBox().getWidth();
double height = page.getMediaBox().getHeight();
System.out.println("Page size: " + width + " x " + height + " pt");
}标准A4为595×842分;美国字母是612 ×792分.
Artifacts
关于 Artifact 类型页面装饰:头条,脚本,水印和 背景图像.文物是PDF规范中定义的非内容元素.
代一个页面的文物集合,以检查每个装饰品的类型和子类别:
try (Document doc = new Document("input.pdf")) {
PageCollection pages = doc.getPages();
Page page = pages.get(1);
for (Artifact artifact : page.getArtifacts()) {
System.out.println(artifact.getArtifactType() + " / " + artifact.getSubtype());
}
}嵌入式文件
EmbeddedFileCollection,通过: Document.getEmbeddedFiles(),管理文件 附录文件嵌入到PDF文档中. 使用 size() 计算附属物.
try (Document doc = new Document("document.pdf")) {
EmbeddedFileCollection files = doc.getEmbeddedFiles();
int count = files.size();
System.out.println("Embedded files: " + count);
}页面数量
使用情况 PageCollection.getCount() 或是 PageCollection.size() 确定总数 文件的页面数量:
try (Document doc = new Document("input.pdf")) {
int pageCount = doc.getPages().getCount();
System.out.println("Total pages: " + pageCount);
}