6
6
import com .itextpdf .kernel .pdf .PdfWriter ;
7
7
import com .itextpdf .kernel .pdf .xobject .PdfImageXObject ;
8
8
import com .itextpdf .kernel .utils .CompareTool ;
9
- import com .itextpdf .test . annotations . type . IntegrationTest ;
9
+ import com .itextpdf .layout . element . Cell ;
10
10
import com .itextpdf .layout .element .Div ;
11
11
import com .itextpdf .layout .element .Image ;
12
12
import com .itextpdf .layout .element .Paragraph ;
13
+ import com .itextpdf .layout .element .Table ;
13
14
import com .itextpdf .layout .element .Text ;
14
15
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 ;
15
19
16
20
import java .io .File ;
17
21
import java .io .FileOutputStream ;
18
22
import java .io .IOException ;
19
23
20
- import com .itextpdf .test .annotations .LogMessage ;
21
- import com .itextpdf .test .annotations .LogMessages ;
22
24
import org .junit .Assert ;
23
25
import org .junit .BeforeClass ;
24
26
import org .junit .Test ;
@@ -238,7 +240,6 @@ public void imageTest07() throws IOException, InterruptedException {
238
240
@ LogMessage (messageTemplate = LogMessageConstant .ELEMENT_DOES_NOT_FIT_AREA )
239
241
})
240
242
public void imageTest08 () throws IOException , InterruptedException {
241
-
242
243
String outFileName = destinationFolder + "imageTest08.pdf" ;
243
244
String cmpFileName = sourceFolder + "cmp_imageTest08.pdf" ;
244
245
@@ -259,4 +260,32 @@ public void imageTest08() throws IOException, InterruptedException {
259
260
260
261
Assert .assertNull (new CompareTool ().compareByContent (outFileName , cmpFileName , destinationFolder , "diff" ));
261
262
}
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
+ }
262
291
}
0 commit comments