66import com .itextpdf .kernel .pdf .PdfWriter ;
77import com .itextpdf .kernel .pdf .xobject .PdfImageXObject ;
88import com .itextpdf .kernel .utils .CompareTool ;
9- import com .itextpdf .test . annotations . type . IntegrationTest ;
9+ import com .itextpdf .layout . element . Cell ;
1010import com .itextpdf .layout .element .Div ;
1111import com .itextpdf .layout .element .Image ;
1212import com .itextpdf .layout .element .Paragraph ;
13+ import com .itextpdf .layout .element .Table ;
1314import com .itextpdf .layout .element .Text ;
1415import 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
1620import java .io .File ;
1721import java .io .FileOutputStream ;
1822import java .io .IOException ;
1923
20- import com .itextpdf .test .annotations .LogMessage ;
21- import com .itextpdf .test .annotations .LogMessages ;
2224import org .junit .Assert ;
2325import org .junit .BeforeClass ;
2426import 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}
0 commit comments