Skip to content

Commit

Permalink
PDFBOX-5927: add test
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1922610 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
THausherr committed Dec 20, 2024
1 parent b254377 commit 187a3a0
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
13 changes: 13 additions & 0 deletions pdfbox/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,19 @@
<sha512>995b25abc41bcb3e89f93d1495d4e178010c7dfbbdd55fed71de395d3798a83575b619c333a22386d441152f821debffd01c26494bef86cb35ef0d04e0198a3b</sha512>
</configuration>
</execution>
<execution>
<id>PDFBOX-5927</id>
<phase>generate-test-resources</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>https://issues.apache.org/jira/secure/attachment/13073586/SO79293670.pdf</url>
<outputDirectory>${project.build.directory}/pdfs</outputDirectory>
<outputFileName>PDFBOX-5927.pdf</outputFileName>
<sha512>73cabf224a56cd7256262245d5edb79729401a7485e420a0d66c931bdb22cbd3a08eeaebf73b718fd68dc458cfd0008c168c234ae7827d62cb0448b0c36af1c5</sha512>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
*/
package org.apache.pdfbox.pdfwriter;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;

import org.apache.pdfbox.Loader;
import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.pdmodel.PDDocument;
Expand All @@ -28,14 +34,13 @@
import org.apache.pdfbox.pdmodel.font.PDType1Font;
import org.apache.pdfbox.pdmodel.font.Standard14Fonts.FontName;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;
import org.junit.jupiter.api.Test;
import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
import org.apache.pdfbox.pdmodel.interactive.form.PDCheckBox;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.io.File;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;

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

/**
* Check that the bug from PDFBOX-5927 is fixed. This one caused a dictionary key to be written
* as an indirect object in an object stream.
*
* @throws IOException
*/
@Test
void testPDFBox5927() throws IOException
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (PDDocument doc = Loader.loadPDF(new File("target/pdfs","PDFBOX-5927.pdf")))
{
doc.save(baos);
}
try (PDDocument doc = Loader.loadPDF(baos.toByteArray()))
{
PDAcroForm acroForm = doc.getDocumentCatalog().getAcroForm();
PDCheckBox cb = (PDCheckBox) acroForm.getField("chkPrivacy1");
assertTrue(cb.isChecked());
}
}
}

0 comments on commit 187a3a0

Please sign in to comment.