itext flat field增加文件大小

时间:2016-12-17 22:55:27

标签: itext

我发现在提交bd5c1fdee48184fa97c4b12afb4370712acf1263之后,如果我使用此sample pdf运行此代码,我会得到一个12MB的文件。

PdfReader reader = new PdfReader("/tmp/tpl2.pdf");
AcroFields fields = r.getAcroFields();
if(fields != null && fields.getFields() != null && fields.getFields().size() > 0) {
    OutputStream out = null;
    out = new FileOutputStream("/tmp/testDim.pdf");
    PdfStamper stamp = new PdfStamper(r, out);
    stamp.setFormFlattening(true);
    AcroFields form = stamp.getAcroFields();

    Set<Entry<String,Item>> map = form.getFields().entrySet();
    for (Entry<String, Item> e : map) {
        form.setField(e.getKey(), e.getKey());
    }

    stamp.close();
    out.close();
}
r.close();

如果我在5.5.10上执行以下补丁,则会获得144kB文件。

diff --git a/itext/src/main/java/com/itextpdf/text/pdf/PdfStamperImp.java b/itext/src/main/java/com/itextpdf/text/pdf/PdfStamperImp.java
index 2309003..dc58a63 100644
--- a/itext/src/main/java/com/itextpdf/text/pdf/PdfStamperImp.java
+++ b/itext/src/main/java/com/itextpdf/text/pdf/PdfStamperImp.java
@@ -929,7 +929,9 @@
                 PdfDictionary appDic = merged.getAsDict(PdfName.AP);
                 PdfObject as_n = null;
                 if (appDic != null) {
-                    as_n = appDic.getAsStream(PdfName.N);
+                    as_n = appDic.getDirectObject(PdfName.N);
+                    if (as_n == null)
+                        as_n = appDic.getAsStream(PdfName.N);
                     if (as_n == null)
                         as_n = appDic.getAsDict(PdfName.N);
                 }

我做补丁是因为我试图恢复提交中唯一的相关部分,但我不知道它是否安全,你认为它是否可以。

由于

0 个答案:

没有答案