Skip to content

Commit bccbd88

Browse files
committed
PDFBOX-5797: add test
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1922558 13f79535-47bb-0310-9956-ffa450edef68
1 parent eae97f6 commit bccbd88

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroFormTest.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.apache.pdfbox.pdmodel.PDResources;
4343
import org.apache.pdfbox.pdmodel.common.PDRectangle;
4444
import org.apache.pdfbox.pdmodel.font.PDFont;
45+
import org.apache.pdfbox.pdmodel.font.PDType0Font;
4546
import org.apache.pdfbox.pdmodel.font.PDType1Font;
4647
import org.apache.pdfbox.pdmodel.font.Standard14Fonts.FontName;
4748
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;
@@ -53,6 +54,7 @@
5354
import org.junit.jupiter.api.BeforeEach;
5455
import org.junit.jupiter.api.Test;
5556
import org.junit.jupiter.api.Assertions;
57+
import static org.junit.jupiter.api.Assertions.fail;
5658

5759
/**
5860
* Test for the PDButton class.
@@ -120,7 +122,7 @@ void testFlatten() throws IOException
120122
if (!TestPDFToImage.doTestFile(file, IN_DIR.getAbsolutePath(), OUT_DIR.getAbsolutePath()))
121123
{
122124
// don't fail, rendering is different on different systems, result must be viewed manually
123-
System.out.println("Rendering of " + file + " failed or is not identical to expected rendering in " + IN_DIR + " directory");
125+
fail("Rendering of " + file + " failed or is not identical to expected rendering in " + IN_DIR + " directory");
124126
}
125127

126128
}
@@ -154,7 +156,7 @@ void testFlattenWidgetNoRef() throws IOException
154156
if (!TestPDFToImage.doTestFile(file, IN_DIR.getAbsolutePath(), OUT_DIR.getAbsolutePath()))
155157
{
156158
// don't fail, rendering is different on different systems, result must be viewed manually
157-
System.out.println("Rendering of " + file + " failed or is not identical to expected rendering in " + IN_DIR + " directory");
159+
fail("Rendering of " + file + " failed or is not identical to expected rendering in " + IN_DIR + " directory");
158160
}
159161
}
160162

@@ -407,6 +409,33 @@ void testPDFBox3347() throws IOException, URISyntaxException
407409
}
408410
}
409411

412+
/***
413+
* PDFBOX-5797: Check that Sejda generated files have their widget /DA entries changed.
414+
*/
415+
@Test
416+
void testPDFBox5797() throws IOException
417+
{
418+
try (PDDocument doc = Loader.loadPDF(new File(
419+
"src/test/resources/org/apache/pdfbox/pdmodel/interactive/annotation/PDFBOX-5797-SO79271803.pdf")))
420+
{
421+
PDType0Font load = PDType0Font.load(doc,
422+
PDAcroFormFromAnnotsTest.class.getResourceAsStream("/org/apache/pdfbox/resources/ttf/LiberationSans-Regular.ttf"),
423+
false);
424+
425+
PDAcroForm acroForm = doc.getDocumentCatalog().getAcroForm();
426+
PDResources resources = acroForm.getDefaultResources();
427+
String fontName = resources.add(load).getName();
428+
String defaultAppearanceString = "/" + fontName + " 12 Tf 0 g";
429+
430+
PDTextField myField = (PDTextField) acroForm.getField("Name");
431+
myField.setDefaultAppearance(defaultAppearanceString);
432+
myField.getWidgets().get(0).setAppearance(null);
433+
myField.setValue("ŞŞ"); // Text with the Ş character made it crash
434+
435+
assertEquals("ŞŞ", myField.getValue());
436+
}
437+
}
438+
410439
@AfterEach
411440
public void tearDown() throws IOException
412441
{

0 commit comments

Comments
 (0)