Skip to content

Commit 56809ea

Browse files
committed
Remove FLUSH_ON_DRAW by default for layout images created by io images
Image layout element can be reused, so it is incorrect to flush underlying Image XObject on draw. The property is left, though, allowing manual flushing for optimization IEA-13
1 parent 7fc5f23 commit 56809ea

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

layout/src/main/java/com/itextpdf/layout/element/Image.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ public Image(PdfFormXObject xObject, float x, float y) {
9999
*/
100100
public Image(com.itextpdf.io.image.Image img) {
101101
this(new PdfImageXObject(checkImageType(img)));
102-
setProperty(Property.FLUSH_ON_DRAW, true);
103102
}
104103

105104
/**

layout/src/test/java/com/itextpdf/layout/ImageTest.java

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@
66
import com.itextpdf.kernel.pdf.PdfWriter;
77
import com.itextpdf.kernel.pdf.xobject.PdfImageXObject;
88
import com.itextpdf.kernel.utils.CompareTool;
9-
import com.itextpdf.test.annotations.type.IntegrationTest;
9+
import com.itextpdf.layout.element.Cell;
1010
import com.itextpdf.layout.element.Div;
1111
import com.itextpdf.layout.element.Image;
1212
import com.itextpdf.layout.element.Paragraph;
13+
import com.itextpdf.layout.element.Table;
1314
import com.itextpdf.layout.element.Text;
1415
import com.itextpdf.test.ExtendedITextTest;
16+
import com.itextpdf.test.annotations.LogMessage;
17+
import com.itextpdf.test.annotations.LogMessages;
18+
import com.itextpdf.test.annotations.type.IntegrationTest;
1519

1620
import java.io.File;
1721
import java.io.FileOutputStream;
1822
import java.io.IOException;
1923

20-
import com.itextpdf.test.annotations.LogMessage;
21-
import com.itextpdf.test.annotations.LogMessages;
2224
import org.junit.Assert;
2325
import org.junit.BeforeClass;
2426
import org.junit.Test;
@@ -238,7 +240,6 @@ public void imageTest07() throws IOException, InterruptedException {
238240
@LogMessage(messageTemplate = LogMessageConstant.ELEMENT_DOES_NOT_FIT_AREA)
239241
})
240242
public void imageTest08() throws IOException, InterruptedException {
241-
242243
String outFileName = destinationFolder + "imageTest08.pdf";
243244
String cmpFileName = sourceFolder + "cmp_imageTest08.pdf";
244245

@@ -259,4 +260,32 @@ public void imageTest08() throws IOException, InterruptedException {
259260

260261
Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, destinationFolder, "diff"));
261262
}
263+
264+
/**
265+
* Image can be reused in layout, so flushing it on the very first draw is a bad thing.
266+
*/
267+
@Test
268+
public void flushOnDrawTest() throws IOException, InterruptedException {
269+
String outFileName = destinationFolder + "flushOnDrawTest.pdf";
270+
String cmpFileName = sourceFolder + "cmp_flushOnDrawTest.pdf";
271+
272+
int rowCount = 60;
273+
FileOutputStream fos = new FileOutputStream(outFileName);
274+
PdfWriter writer = new PdfWriter(fos);
275+
PdfDocument pdfDoc = new PdfDocument(writer);
276+
com.itextpdf.layout.Document document = new com.itextpdf.layout.Document(pdfDoc);
277+
Image img = new Image(ImageFactory.getImage(sourceFolder + "Desert.jpg"));
278+
Table table = new Table(8);
279+
table.setWidthPercent(100);
280+
for (int k = 0; k < rowCount; k++) {
281+
for (int j = 0; j < 7; j++)
282+
{ table.addCell("Hello"); }
283+
Cell c = new Cell().add(img.setWidthPercent(50));
284+
table.addCell(c);
285+
}
286+
document.add(table);
287+
document.close();
288+
289+
Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, destinationFolder, "diff"));
290+
}
262291
}
Binary file not shown.

0 commit comments

Comments
 (0)