Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support of PdfIndirectObject for coordinates in /Rect, /BBox #1113

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions openpdf/src/main/java/com/lowagie/text/pdf/PdfStamperImp.java
Original file line number Diff line number Diff line change
Expand Up @@ -979,8 +979,8 @@ void flatFields() {

if (bboxRaw != null && rectRaw != null) {
transformNeeded = true;
PdfRectangle bbox = new PdfRectangle(bboxRaw);
PdfRectangle rect = new PdfRectangle(rectRaw);
PdfRectangle bbox = new PdfRectangle(PdfReader.getNormalizedRectangle(bboxRaw));
PdfRectangle rect = new PdfRectangle(PdfReader.getNormalizedRectangle(rectRaw));

float rectWidth = rect.width();
float rectHeight = rect.height();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -127,4 +131,38 @@ void testFlattenTextfieldsWithRotationAndMatrix() throws IOException {
pdfReader.close();
}
}

@Test
void testFlattenFieldsWithPdfIndirectObjectInRect() throws IOException {
final Path targetFilePath = Paths.get("target/indirect_object_in_rectangle-flattened.pdf");
try (InputStream resource = getClass().getResourceAsStream(
"/flattening/indirect_object_in_rectangle.pdf")) {
Assertions.assertNotNull(resource, "File could not be found!");
OutputStream fos = Files.newOutputStream(targetFilePath);

PdfReader pdfReader = new PdfReader(resource);
PdfStamper stamper = new PdfStamper(pdfReader, fos);

stamper.getAcroFields().setGenerateAppearances(true);
stamper.setFormFlattening(true);

pdfReader.close();
stamper.close();
}
//Verify no form fields left (the correct shape is difficult to verify...)
try (InputStream resource = Files.newInputStream(targetFilePath)) {

Assertions.assertNotNull(resource, "File could not be found!");
PdfReader pdfReader = new PdfReader(resource);

PdfDictionary acroForm = (PdfDictionary) PdfReader.getPdfObjectRelease(
pdfReader.getCatalog().get(PdfName.ACROFORM));
Assertions.assertTrue(acroForm == null
|| acroForm.getAsArray(PdfName.FIELDS) == null
|| acroForm.getAsArray(PdfName.FIELDS).isEmpty());

pdfReader.close();
}
}

}
Binary file not shown.
Loading