|
16 | 16 | */ |
17 | 17 | package org.apache.pdfbox.pdfwriter; |
18 | 18 |
|
| 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 | + |
19 | 25 | import org.apache.pdfbox.Loader; |
20 | 26 | import org.apache.pdfbox.cos.COSName; |
21 | 27 | import org.apache.pdfbox.pdmodel.PDDocument; |
|
28 | 34 | import org.apache.pdfbox.pdmodel.font.PDType1Font; |
29 | 35 | import org.apache.pdfbox.pdmodel.font.Standard14Fonts.FontName; |
30 | 36 | 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; |
32 | 39 |
|
33 | 40 | import static org.junit.jupiter.api.Assertions.assertEquals; |
34 | 41 | 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; |
39 | 44 |
|
40 | 45 | /** |
41 | 46 | * 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 |
258 | 263 | } |
259 | 264 | } |
260 | 265 |
|
| 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 | + } |
261 | 287 | } |
0 commit comments