Skip to content

Commit

Permalink
PDFBOX-5797: add test
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1922558 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
THausherr committed Dec 17, 2024
1 parent eae97f6 commit bccbd88
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.apache.pdfbox.pdmodel.PDResources;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.font.PDFont;
import org.apache.pdfbox.pdmodel.font.PDType0Font;
import org.apache.pdfbox.pdmodel.font.PDType1Font;
import org.apache.pdfbox.pdmodel.font.Standard14Fonts.FontName;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;
Expand All @@ -53,6 +54,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;
import static org.junit.jupiter.api.Assertions.fail;

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

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

Expand Down Expand Up @@ -407,6 +409,33 @@ void testPDFBox3347() throws IOException, URISyntaxException
}
}

/***
* PDFBOX-5797: Check that Sejda generated files have their widget /DA entries changed.
*/
@Test
void testPDFBox5797() throws IOException
{
try (PDDocument doc = Loader.loadPDF(new File(
"src/test/resources/org/apache/pdfbox/pdmodel/interactive/annotation/PDFBOX-5797-SO79271803.pdf")))
{
PDType0Font load = PDType0Font.load(doc,
PDAcroFormFromAnnotsTest.class.getResourceAsStream("/org/apache/pdfbox/resources/ttf/LiberationSans-Regular.ttf"),
false);

PDAcroForm acroForm = doc.getDocumentCatalog().getAcroForm();
PDResources resources = acroForm.getDefaultResources();
String fontName = resources.add(load).getName();
String defaultAppearanceString = "/" + fontName + " 12 Tf 0 g";

PDTextField myField = (PDTextField) acroForm.getField("Name");
myField.setDefaultAppearance(defaultAppearanceString);
myField.getWidgets().get(0).setAppearance(null);
myField.setValue("ŞŞ"); // Text with the Ş character made it crash

assertEquals("ŞŞ", myField.getValue());
}
}

@AfterEach
public void tearDown() throws IOException
{
Expand Down
Binary file not shown.

0 comments on commit bccbd88

Please sign in to comment.