Skip to content

Commit 187a3a0

Browse files
committed
PDFBOX-5927: add test
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1922610 13f79535-47bb-0310-9956-ffa450edef68
1 parent b254377 commit 187a3a0

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

pdfbox/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,19 @@
790790
<sha512>995b25abc41bcb3e89f93d1495d4e178010c7dfbbdd55fed71de395d3798a83575b619c333a22386d441152f821debffd01c26494bef86cb35ef0d04e0198a3b</sha512>
791791
</configuration>
792792
</execution>
793+
<execution>
794+
<id>PDFBOX-5927</id>
795+
<phase>generate-test-resources</phase>
796+
<goals>
797+
<goal>wget</goal>
798+
</goals>
799+
<configuration>
800+
<url>https://issues.apache.org/jira/secure/attachment/13073586/SO79293670.pdf</url>
801+
<outputDirectory>${project.build.directory}/pdfs</outputDirectory>
802+
<outputFileName>PDFBOX-5927.pdf</outputFileName>
803+
<sha512>73cabf224a56cd7256262245d5edb79729401a7485e420a0d66c931bdb22cbd3a08eeaebf73b718fd68dc458cfd0008c168c234ae7827d62cb0448b0c36af1c5</sha512>
804+
</configuration>
805+
</execution>
793806
</executions>
794807
</plugin>
795808
</plugins>

pdfbox/src/test/java/org/apache/pdfbox/pdfwriter/COSDocumentCompressionTest.java

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
*/
1717
package org.apache.pdfbox.pdfwriter;
1818

19+
import java.io.ByteArrayOutputStream;
20+
import java.io.File;
21+
import java.io.IOException;
22+
import java.util.List;
23+
import java.util.Map;
24+
1925
import org.apache.pdfbox.Loader;
2026
import org.apache.pdfbox.cos.COSName;
2127
import org.apache.pdfbox.pdmodel.PDDocument;
@@ -28,14 +34,13 @@
2834
import org.apache.pdfbox.pdmodel.font.PDType1Font;
2935
import org.apache.pdfbox.pdmodel.font.Standard14Fonts.FontName;
3036
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;
31-
import org.junit.jupiter.api.Test;
37+
import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
38+
import org.apache.pdfbox.pdmodel.interactive.form.PDCheckBox;
3239

3340
import static org.junit.jupiter.api.Assertions.assertEquals;
3441
import static org.junit.jupiter.api.Assertions.assertNotNull;
35-
36-
import java.io.File;
37-
import java.util.List;
38-
import java.util.Map;
42+
import static org.junit.jupiter.api.Assertions.assertTrue;
43+
import org.junit.jupiter.api.Test;
3944

4045
/**
4146
* This test attempts to save different documents compressed, without causing errors, it also checks, whether the PDF is
@@ -258,4 +263,25 @@ void testAlteredDoc() throws Exception
258263
}
259264
}
260265

266+
/**
267+
* Check that the bug from PDFBOX-5927 is fixed. This one caused a dictionary key to be written
268+
* as an indirect object in an object stream.
269+
*
270+
* @throws IOException
271+
*/
272+
@Test
273+
void testPDFBox5927() throws IOException
274+
{
275+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
276+
try (PDDocument doc = Loader.loadPDF(new File("target/pdfs","PDFBOX-5927.pdf")))
277+
{
278+
doc.save(baos);
279+
}
280+
try (PDDocument doc = Loader.loadPDF(baos.toByteArray()))
281+
{
282+
PDAcroForm acroForm = doc.getDocumentCatalog().getAcroForm();
283+
PDCheckBox cb = (PDCheckBox) acroForm.getField("chkPrivacy1");
284+
assertTrue(cb.isChecked());
285+
}
286+
}
261287
}

0 commit comments

Comments
 (0)