FOP-2933: PDF to PDF checkbox missing
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop-pdf-images/trunk@1877369 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxAdapter.java b/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxAdapter.java
index 0841c6d..81caf32 100644
--- a/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxAdapter.java
+++ b/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxAdapter.java
@@ -710,6 +710,7 @@
PDFObject clonedAnnot = (PDFObject) cloneForNewDocument(annot1, annot1, exclude);
if (clonedAnnot instanceof PDFDictionary) {
+ cloneAnnotParent(annot1, (PDFDictionary) clonedAnnot, exclude);
clonedAnnot.setParent(targetPage);
PDFBoxAdapterUtil.updateAnnotationLink((PDFDictionary) clonedAnnot);
}
@@ -719,6 +720,17 @@
return fields;
}
+ private void cloneAnnotParent(Object annot1, PDFDictionary clonedAnnot, Collection<COSName> exclude)
+ throws IOException {
+ if (annot1 instanceof COSObject) {
+ COSDictionary dictionary = (COSDictionary) ((COSObject) annot1).getObject();
+ COSBase parent = dictionary.getItem(COSName.PARENT);
+ if (parent != null) {
+ clonedAnnot.put(COSName.PARENT.getName(), cloneForNewDocument(parent, parent, exclude));
+ }
+ }
+ }
+
private COSDictionary getField(COSObject fieldObject, Set<COSObject> fields) {
COSDictionary field = (COSDictionary) fieldObject.getObject();
COSObject parent;
diff --git a/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java b/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java
index 5ffd10b..4b9d5e6 100644
--- a/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java
+++ b/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java
@@ -120,6 +120,7 @@
private static final String SMASK = "test/resources/smask.pdf";
private static final String TYPE0TT = "test/resources/type0tt.pdf";
private static final String TYPE0CFF = "test/resources/type0cff.pdf";
+ private static final String ACCESSIBLERADIOBUTTONS = "test/resources/accessibleradiobuttons.pdf";
private static PDFPage getPDFPage(PDFDocument doc) {
final Rectangle2D r = new Rectangle2D.Double();
@@ -277,6 +278,27 @@
doc.close();
}
+
+ @Test
+ public void testAnnot3() throws Exception {
+ PDFDocument pdfdoc = new PDFDocument("");
+ PDFPage pdfpage = getPDFPage(pdfdoc);
+ pdfpage.setDocument(pdfdoc);
+ pdfpage.setObjectNumber(1);
+ PDFBoxAdapter adapter = new PDFBoxAdapter(pdfpage, new HashMap(), new HashMap<Integer, PDFArray>());
+ PDDocument doc = PDDocument.load(new File(ACCESSIBLERADIOBUTTONS));
+ PDPage page = doc.getPage(0);
+ AffineTransform at = new AffineTransform();
+ Rectangle r = new Rectangle(0, 1650, 842000, 595000);
+ adapter.createStreamFromPDFBoxPage(doc, page, "key", at, null, r);
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ pdfdoc.output(os);
+ String out = os.toString("UTF-8");
+ Assert.assertTrue(out.contains("/Parent "));
+ Assert.assertTrue(out.contains("/Kids "));
+ doc.close();
+ }
+
@Test
public void testLink() throws Exception {
PDFDocument pdfdoc = new PDFDocument("");
diff --git a/test/resources/accessibleradiobuttons.pdf b/test/resources/accessibleradiobuttons.pdf
new file mode 100644
index 0000000..98c5d12
--- /dev/null
+++ b/test/resources/accessibleradiobuttons.pdf
Binary files differ