- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我想创建一个充满 PDF-As 的 ZipOutputStream。我正在使用 iText(版本 5.5.7)。对于超过 1000 个 pdf 条目,我在 doc.close() 上遇到 OutOfMemory 异常并且找不到泄漏。
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(baos));
zos.setEncoding("Cp850");
for (MyObject o : objects) {
try {
String pdfFilename = o.getName() + ".pdf";
zos.putNextEntry(new ZipEntry(pdfFilename));
pdfBuilder.buildPdfADocument(zos);
zos.closeEntry();
} ...
PDF生成器
public void buildPdfADocument(org.apache.tools.zip.ZipOutputStream zos){
Document doc = new Document(PageSize.A4);
PdfAWriter writer = PdfAWriter.getInstance(doc, zos, PdfAConformanceLevel.PDF_A_1B);
writer.setCloseStream(false); // to not close my zos
writer.setViewerPreferences(PdfWriter.ALLOW_PRINTING | PdfWriter.PageLayoutSinglePage);
writer.createXmpMetadata();
doc.open();
// adding Element's to doc
// with flushContent() on PdfPTables
InputStream sRGBprofile = servletContext.getResourceAsStream("/WEB-INF/conf/AdobeRGB1998.icc");
ICC_Profile icc = ICC_Profile.getInstance(sRGBprofile);
writer.setOutputIntents("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", icc);
//try to close/flush everything possible
doc.close();
writer.setXmpMetadata(null);
writer.flush();
writer.close();
if(sRGBprofile != null){
sRGBprofile.close();
}
}
有什么建议可以解决吗?我忘记了什么吗?我已经尝试过使用 java ZipOutputStream,但它有任何不同。
感谢您的回答!我了解 ByteOutputStream 的问题,但我不确定在我的案例中什么是最好的方法。这是一个 Web 应用程序,我需要以某种方式将 zip 打包到数据库 blob 中。
我现在正在做的是使用 iText 将 PDF 直接创建到 ZipOutputStream 并将相应的 ByteArrayOutputSteam 的字节数组保存到 blob。我看到的选项是:
将我的数据拆分为 500 个对象包,将前 500 个 PDF 保存到数据库,然后打开 zip 并添加接下来的 500 个,依此类推......但我认为这会让我遇到与现在相同的情况,即内存中打开的流太大。
尝试将 PDF 保存在服务器上(不确定是否有足够的空间),创建临时 zip 文件,然后将字节提交到 blob...
有什么建议/想法吗?
最佳答案
这是因为您的 ZipOutputStream
由 ByteArrayOutputStream 支持,所以即使关闭条目也会将完整的 ZIP 内容保留在内存中。
关于java - iText - OutOfMemory 创建超过 1000 个 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32891931/
iText 文档指出它只包含特定的字体子集,但从未说明它们是什么。有没有人知道 iText 中默认包含哪些字体? (我在网上搜索过,在任何地方都找不到这个字体列表!) 最佳答案 它可能指的是PDF S
我使用固定列宽创建了下表,如下所示, Table headerTable = new Table(new float[]{5,5,5}); headerTable.setWidthPercent(
我正在尝试使用 iText 缩放图像(在新的 PDF 文档上)以使其填充页面宽度而不拉伸(stretch),这样它可能需要几页。 我找到了很多解决方案,但它们都非常复杂,而且我真的不喜欢那样编码。到目
我正在使用 Flying Saucer/iText 生成报告。现在报告有一个条件,如果特定条件发生,报告应该移动到 pdf 的下一页,并在 PDF 上添加数据等等。 问候帕万 最佳答案 您必须使用 c
我正在使用 Flying Saucer/iText 生成报告。现在报告有一个条件,如果特定条件发生,报告应该移动到 pdf 的下一页,并在 PDF 上添加数据等等。 问候帕万 最佳答案 您必须使用 c
如何使用 iText 找到文档中的行的位置? 假设我有一个 PDF 文档中的表格,并且想要阅读其中的内容;我想找到细胞的确切位置。为了做到这一点,我想我可能会找到线条的交点。 最佳答案 我认为您使用
请找到下面的代码。 public class MakingFieldReadOnly implements PdfPCellEvent { /** The resulting PDF. */
在 iText 5 中有一个名为 getVerticalPosition() 的方法,它给出了下一个写入对象在页面上的位置。作为回答这个问题 How to find out the current c
抱歉,如果有类似我的帖子,但我是这个论坛的新手,我还没有找到它。 我有动态调整 TextField 大小取决于文本大小的问题。我填写现有的 PDF - 在 AcroForm 中填写字段: form.s
我正在使用 itext 生成 pdf。因此,当页面内容超出时,它会自动创建一个新页面。我想知道它是否创建了一个新页面。如果是,我想在页面顶部添加一些图像。 List paylist =new List
我的 有问题固定 表格左侧和右侧的边距。 我想删除该边距并使用没有边距或填充的所有工作表。我该怎么办? 我刚刚试过这个,但对我不起作用: cell.setPaddingLeft(0); cell.se
我有 2 行,我想对齐(证明)它们。 我有这个代码: Paragraph p=new Paragraph(ANC,fontFootData); p.setLeading(1, 1);
我有这样的场景。 我有一个生成 PDF 的应用程序,需要对其进行签名。 我们没有用于签署文档的证书,因为它们位于 HSM 中,而我们使用证书的唯一方法是使用 Web 服务。 此网络服务提供两个选项,发
我需要实现一个看起来像图片中的表格,列之间有空间。我试过: cell.setPaddingLeft(10); cell.setMarginLeft(10); extractio
我需要实现一个看起来像图片中的表格,列之间有空间。我试过: cell.setPaddingLeft(10); cell.setMarginLeft(10); extractio
我需要使用 Java 的 iText 库创建一个 PDF 文档。我还需要包括一些复选框,这些复选框根据某些类变量的值打开/关闭。我找到了一些关于交互式表单的示例,但我不需要这种复杂程度:只需将一些复选
我正在开发一个系统,我必须在其中将一些图像添加到现有的 PDF 文档中。 这适用于 iText 5.1.3,但由于某种原因,在包含扫描图像的 PDF 中,它不会添加任何图像。 这是 PDF Docum
我们正在研究信息提取,我们想使用iText。 我们正在探索 iText。根据我们查阅过的文献,iText 是最好的工具。是否可以从 iText 中每行的 pdf 中提取文本?我在与我的相关的 stac
我已经创建了一个带有一些文本字段的 pdf 文档。我可以使用 Adobe 阅读器填充这些文本字段并将这些值保存在该文件中。 我的问题是,我可以使用 iText 以编程方式执行此操作吗?如果可能,请
我正在使用 iText 5 表创建标签(如 Avery 标签)。标签元素的定位需要一些非常严格的公差,以便适合标签上的所有内容。我的问题是标签上有多个区域为 PdfPCells。我需要将文本放入这些区
我是一名优秀的程序员,十分优秀!