内容流运营商
本指南说明如何使用PDF内容流操作程序访问和操纵: ContentStreamParser 及其他 ContentStreamBuilder 在 Aspose.PDF FOSS 对于 Java . 你将学习阅读原始页面内容字节,并使用解析器检查图纸. 命令. 我们的任务是:.
内容流
内容流中的操作符序列. 每个字段的编码过程中,每个字节都会被加密为一个数据库. Page 通过该网站向其内容运营商提供访问. getContents() 财产.
ContentStreamParser
ContentStreamParser 将原始内容流字节解析为操作员对象, 允许页面绘图命令的程序检查.通过原始字节从 page.getContents().toByteArray() 给解析器构造程序:
try (Document doc = new Document("input.pdf")) {
PageCollection pages = doc.getPages();
Page page = pages.get(1);
byte[] contentBytes = page.getContents().toByteArray();
ContentStreamParser parser = new ContentStreamParser(contentBytes);
// Iterate over parsed operators
}ContentStreamBuilder
ContentStreamBuilder 创建新的内容流,用于嵌入一个 Page. 使用情况 ContentStreamBuilder 在构建页面内容时, 程序化而不是 构建后,将其分配到现有流. 页面并保存文件.
运营商参考
文件内容流运营商定义在ISO 32000-1:2008表A.1.常见. 操作符包括文本操作 (BT, ET, Tf, Tj),图形状态操作器. (q, Q, cm),路线运营商 (m, l, h, f, S).
内容流运营商遵循PDF规范 (ISO 32000-1:2008,第8段). 使用情况 ContentStreamParser 在现有流中对运算器进行代.
访问原始页面内容
要读出页面内容流的原始字节,请调用 page.getContents().toByteArray(). 通过数据库的检查,解码或传递给 ContentStreamParser:
try (Document doc = new Document("input.pdf")) {
PageCollection pages = doc.getPages();
Page page = pages.get(1);
byte[] contentBytes = page.getContents().toByteArray();
System.out.println("Content stream size: " + contentBytes.length + " bytes");
}