diff options
author | Simon Steiner <ssteiner@apache.org> | 2023-06-13 08:25:22 +0100 |
---|---|---|
committer | Simon Steiner <ssteiner@apache.org> | 2023-07-21 11:10:41 +0100 |
commit | 3dd36e9bb26df83fa8677425f7f16e1d53001409 (patch) | |
tree | 76f855a1605d34df0dbdeca11fba54a91f9059fa /fop-core | |
parent | 05f8a2c9d2084b29b7ddf49a25d6a8e028243b7c (diff) | |
download | xmlgraphics-fop-3dd36e9bb26df83fa8677425f7f16e1d53001409.tar.gz xmlgraphics-fop-3dd36e9bb26df83fa8677425f7f16e1d53001409.zip |
FOP-3140: Merge form fields in external PDFs
Diffstat (limited to 'fop-core')
10 files changed, 52 insertions, 1 deletions
diff --git a/fop-core/src/main/java/org/apache/fop/pdf/PDFDocument.java b/fop-core/src/main/java/org/apache/fop/pdf/PDFDocument.java index 2e13e7015..b63039812 100644 --- a/fop-core/src/main/java/org/apache/fop/pdf/PDFDocument.java +++ b/fop-core/src/main/java/org/apache/fop/pdf/PDFDocument.java @@ -176,6 +176,8 @@ public class PDFDocument { private boolean mergeFontsEnabled; + private boolean mergeFormFieldsEnabled; + private boolean linearizationEnabled; private boolean formXObjectEnabled; @@ -432,7 +434,7 @@ public class PDFDocument { * @param obj {@link PDFObject} to add * @return the added {@link PDFObject} added (with its object number set) */ - <T extends PDFObject> T registerTrailerObject(T obj) { + public <T extends PDFObject> T registerTrailerObject(T obj) { assignObjectNumber(obj); addTrailerObject(obj); return obj; @@ -1187,6 +1189,14 @@ public class PDFDocument { } } + public boolean isMergeFormFieldsEnabled() { + return mergeFormFieldsEnabled; + } + + public void setMergeFormFieldsEnabled(boolean mergeFormFieldsEnabled) { + this.mergeFormFieldsEnabled = mergeFormFieldsEnabled; + } + private interface TrailerOutputHelper { void outputStructureTreeElements(OutputStream stream) throws IOException; diff --git a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentHandler.java b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentHandler.java index 5e3ab010e..02c532c1c 100644 --- a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentHandler.java +++ b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFDocumentHandler.java @@ -97,6 +97,7 @@ public class PDFDocumentHandler extends AbstractBinaryWritingIFDocumentHandler { private final PDFDocumentNavigationHandler documentNavigationHandler = new PDFDocumentNavigationHandler(this); + private Map<String, Object> usedFieldNames = new HashMap<>(); private Map<Integer, PDFArray> pageNumbers = new HashMap<Integer, PDFArray>(); private Map<String, PDFReference> contents = new HashMap<String, PDFReference>(); @@ -377,6 +378,10 @@ public class PDFDocumentHandler extends AbstractBinaryWritingIFDocumentHandler { return structureTreeBuilder; } + public Map<String, Object> getUsedFieldNames() { + return usedFieldNames; + } + public Map<Integer, PDFArray> getPageNumbers() { return pageNumbers; } diff --git a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFPainter.java b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFPainter.java index cebd083a8..5478f4490 100644 --- a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFPainter.java +++ b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFPainter.java @@ -245,6 +245,7 @@ public class PDFPainter extends AbstractIFPainter<PDFDocumentHandler> { PDFRenderingContext pdfContext = new PDFRenderingContext( getUserAgent(), generator, getDocumentHandler().getCurrentPage(), getFontInfo()); pdfContext.setMarkedContentInfo(imageMCI); + pdfContext.setUsedFieldNames(getDocumentHandler().getUsedFieldNames()); pdfContext.setPageNumbers(getDocumentHandler().getPageNumbers()); pdfContext.setPdfLogicalStructureHandler(logicalStructureHandler); pdfContext.setCurrentSessionStructElem((PDFStructElem) getContext().getStructureTreeElement()); diff --git a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRendererConfig.java b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRendererConfig.java index 28111ceed..e71072bfe 100644 --- a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRendererConfig.java +++ b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRendererConfig.java @@ -60,6 +60,7 @@ import static org.apache.fop.render.pdf.PDFRendererOption.FILTER_LIST; import static org.apache.fop.render.pdf.PDFRendererOption.FORM_XOBJECT; import static org.apache.fop.render.pdf.PDFRendererOption.LINEARIZATION; import static org.apache.fop.render.pdf.PDFRendererOption.MERGE_FONTS; +import static org.apache.fop.render.pdf.PDFRendererOption.MERGE_FORM_FIELDS; import static org.apache.fop.render.pdf.PDFRendererOption.OUTPUT_PROFILE; import static org.apache.fop.render.pdf.PDFRendererOption.PDF_A_MODE; import static org.apache.fop.render.pdf.PDFRendererOption.PDF_UA_MODE; @@ -150,6 +151,7 @@ public final class PDFRendererConfig implements RendererConfig { parseAndPut(OUTPUT_PROFILE, cfg); parseAndPut(DISABLE_SRGB_COLORSPACE, cfg); parseAndPut(MERGE_FONTS, cfg); + parseAndPut(MERGE_FORM_FIELDS, cfg); parseAndPut(LINEARIZATION, cfg); parseAndPut(FORM_XOBJECT, cfg); parseAndPut(VERSION, cfg); diff --git a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRendererOption.java b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRendererOption.java index 677256fe4..97834ed2a 100644 --- a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRendererOption.java +++ b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRendererOption.java @@ -87,6 +87,12 @@ public enum PDFRendererOption implements RendererConfigOption { return Boolean.valueOf(value); } }, + MERGE_FORM_FIELDS("merge-form-fields", false) { + @Override + Boolean deserialize(String value) { + return Boolean.valueOf(value); + } + }, LINEARIZATION("linearization", false) { @Override Boolean deserialize(String value) { diff --git a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRendererOptionsConfig.java b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRendererOptionsConfig.java index 02cc9f57d..0360782ef 100644 --- a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRendererOptionsConfig.java +++ b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRendererOptionsConfig.java @@ -36,6 +36,7 @@ import static org.apache.fop.render.pdf.PDFRendererOption.FILTER_LIST; import static org.apache.fop.render.pdf.PDFRendererOption.FORM_XOBJECT; import static org.apache.fop.render.pdf.PDFRendererOption.LINEARIZATION; import static org.apache.fop.render.pdf.PDFRendererOption.MERGE_FONTS; +import static org.apache.fop.render.pdf.PDFRendererOption.MERGE_FORM_FIELDS; import static org.apache.fop.render.pdf.PDFRendererOption.OUTPUT_PROFILE; import static org.apache.fop.render.pdf.PDFRendererOption.PDF_A_MODE; import static org.apache.fop.render.pdf.PDFRendererOption.PDF_UA_MODE; @@ -140,6 +141,10 @@ public final class PDFRendererOptionsConfig { return (Boolean)properties.get(MERGE_FONTS); } + public Boolean getMergeFormFieldsEnabled() { + return (Boolean)properties.get(MERGE_FORM_FIELDS); + } + public Boolean getLinearizationEnabled() { return (Boolean)properties.get(LINEARIZATION); } diff --git a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRenderingContext.java b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRenderingContext.java index b99bcdbfe..8a38d002b 100644 --- a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRenderingContext.java +++ b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRenderingContext.java @@ -40,6 +40,7 @@ public class PDFRenderingContext extends AbstractRenderingContext { private FontInfo fontInfo; private PDFPage page; private MarkedContentInfo mci; + private Map<String, Object> usedFieldNames; private Map<Integer, PDFArray> pageNumbers; private PDFLogicalStructureHandler pdfLogicalStructureHandler; private PDFStructElem currentSessionStructElem; @@ -96,6 +97,14 @@ public class PDFRenderingContext extends AbstractRenderingContext { return mci; } + public Map<String, Object> getUsedFieldNames() { + return usedFieldNames; + } + + public void setUsedFieldNames(Map<String, Object> usedFieldNames) { + this.usedFieldNames = usedFieldNames; + } + public Map<Integer, PDFArray> getPageNumbers() { return pageNumbers; } diff --git a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRenderingUtil.java b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRenderingUtil.java index f2cf5beff..345cc424f 100644 --- a/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRenderingUtil.java +++ b/fop-core/src/main/java/org/apache/fop/render/pdf/PDFRenderingUtil.java @@ -630,6 +630,7 @@ class PDFRenderingUtil { this.pdfDoc.enableAccessibility(userAgent.isAccessibilityEnabled()); pdfDoc.setMergeFontsEnabled(rendererConfig.getMergeFontsEnabled()); + pdfDoc.setMergeFormFieldsEnabled(rendererConfig.getMergeFormFieldsEnabled()); pdfDoc.setLinearizationEnabled(rendererConfig.getLinearizationEnabled()); pdfDoc.setFormXObjectEnabled(rendererConfig.getFormXObjectEnabled()); diff --git a/fop-core/src/test/java/org/apache/fop/apps/PDFRendererConfBuilder.java b/fop-core/src/test/java/org/apache/fop/apps/PDFRendererConfBuilder.java index d21739476..273d97633 100644 --- a/fop-core/src/test/java/org/apache/fop/apps/PDFRendererConfBuilder.java +++ b/fop-core/src/test/java/org/apache/fop/apps/PDFRendererConfBuilder.java @@ -32,6 +32,7 @@ import static org.apache.fop.render.pdf.PDFEncryptionOption.USER_PASSWORD; import static org.apache.fop.render.pdf.PDFRendererOption.DISABLE_SRGB_COLORSPACE; import static org.apache.fop.render.pdf.PDFRendererOption.FILTER_LIST; import static org.apache.fop.render.pdf.PDFRendererOption.FORM_XOBJECT; +import static org.apache.fop.render.pdf.PDFRendererOption.MERGE_FORM_FIELDS; import static org.apache.fop.render.pdf.PDFRendererOption.OUTPUT_PROFILE; import static org.apache.fop.render.pdf.PDFRendererOption.PDF_A_MODE; import static org.apache.fop.render.pdf.PDFRendererOption.PDF_X_MODE; @@ -99,6 +100,11 @@ public final class PDFRendererConfBuilder extends RendererConfBuilder { return this; } + public PDFRendererConfBuilder setMergeFormFieldsEnabled(boolean b) { + createTextElement(MERGE_FORM_FIELDS, String.valueOf(b)); + return this; + } + public final class EncryptionParamsBuilder { private final Element el; diff --git a/fop-core/src/test/java/org/apache/fop/render/pdf/PDFRendererConfigParserTestCase.java b/fop-core/src/test/java/org/apache/fop/render/pdf/PDFRendererConfigParserTestCase.java index 7b81b4db8..e7d7a5c59 100644 --- a/fop-core/src/test/java/org/apache/fop/render/pdf/PDFRendererConfigParserTestCase.java +++ b/fop-core/src/test/java/org/apache/fop/render/pdf/PDFRendererConfigParserTestCase.java @@ -226,4 +226,10 @@ public class PDFRendererConfigParserTestCase public void testErroneousPDFVersionsNotSet() throws Exception { pdfVersionTester(""); } + + @Test + public void testMergeFormFields() throws Exception { + parseConfig(createRenderer().setMergeFormFieldsEnabled(true)); + assertTrue(conf.getConfigOptions().getMergeFormFieldsEnabled()); + } } |