@@ -228,7 +228,7 @@ public virtual void BackgroundXObject() {
228
228
using ( PdfDocument pdfDocument = new PdfDocument ( new PdfWriter ( new FileStream ( outFileName , FileMode . Create
229
229
) ) ) ) {
230
230
iText . Layout . Properties . BackgroundImage backgroundImage = new BackgroundImage . Builder ( ) . SetImage ( CreateFormXObject
231
- ( pdfDocument ) ) . Build ( ) ;
231
+ ( pdfDocument , "itis.jpg" ) ) . Build ( ) ;
232
232
NUnit . Framework . Assert . IsTrue ( backgroundImage . IsRepeatX ( ) ) ;
233
233
NUnit . Framework . Assert . IsTrue ( backgroundImage . IsRepeatY ( ) ) ;
234
234
BackgroundXObjectGenericTest ( filename , backgroundImage , pdfDocument ) ;
@@ -243,7 +243,7 @@ public virtual void BackgroundXObjectWithoutRepeatX() {
243
243
using ( PdfDocument pdfDocument = new PdfDocument ( new PdfWriter ( new FileStream ( outFileName , FileMode . Create
244
244
) ) ) ) {
245
245
iText . Layout . Properties . BackgroundImage backgroundImage = new BackgroundImage . Builder ( ) . SetImage ( CreateFormXObject
246
- ( pdfDocument ) ) . SetBackgroundRepeat ( new BackgroundRepeat ( false , true ) ) . Build ( ) ;
246
+ ( pdfDocument , "itis.jpg" ) ) . SetBackgroundRepeat ( new BackgroundRepeat ( false , true ) ) . Build ( ) ;
247
247
NUnit . Framework . Assert . IsFalse ( backgroundImage . IsRepeatX ( ) ) ;
248
248
NUnit . Framework . Assert . IsTrue ( backgroundImage . IsRepeatY ( ) ) ;
249
249
BackgroundXObjectGenericTest ( filename , backgroundImage , pdfDocument ) ;
@@ -258,7 +258,7 @@ public virtual void BackgroundXObjectWithoutRepeatY() {
258
258
using ( PdfDocument pdfDocument = new PdfDocument ( new PdfWriter ( new FileStream ( outFileName , FileMode . Create
259
259
) ) ) ) {
260
260
iText . Layout . Properties . BackgroundImage backgroundImage = new BackgroundImage . Builder ( ) . SetImage ( CreateFormXObject
261
- ( pdfDocument ) ) . SetBackgroundRepeat ( new BackgroundRepeat ( true , false ) ) . Build ( ) ;
261
+ ( pdfDocument , "itis.jpg" ) ) . SetBackgroundRepeat ( new BackgroundRepeat ( true , false ) ) . Build ( ) ;
262
262
NUnit . Framework . Assert . IsTrue ( backgroundImage . IsRepeatX ( ) ) ;
263
263
NUnit . Framework . Assert . IsFalse ( backgroundImage . IsRepeatY ( ) ) ;
264
264
BackgroundXObjectGenericTest ( filename , backgroundImage , pdfDocument ) ;
@@ -273,7 +273,7 @@ public virtual void BackgroundXObjectWithoutRepeatXY() {
273
273
using ( PdfDocument pdfDocument = new PdfDocument ( new PdfWriter ( new FileStream ( outFileName , FileMode . Create
274
274
) ) ) ) {
275
275
iText . Layout . Properties . BackgroundImage backgroundImage = new BackgroundImage . Builder ( ) . SetImage ( CreateFormXObject
276
- ( pdfDocument ) ) . SetBackgroundRepeat ( new BackgroundRepeat ( false , false ) ) . Build ( ) ;
276
+ ( pdfDocument , "itis.jpg" ) ) . SetBackgroundRepeat ( new BackgroundRepeat ( false , false ) ) . Build ( ) ;
277
277
NUnit . Framework . Assert . IsFalse ( backgroundImage . IsRepeatX ( ) ) ;
278
278
NUnit . Framework . Assert . IsFalse ( backgroundImage . IsRepeatY ( ) ) ;
279
279
BackgroundXObjectGenericTest ( filename , backgroundImage , pdfDocument ) ;
@@ -297,19 +297,55 @@ public virtual void BackgroundXObjectAndImageTest() {
297
297
PdfImageXObject imageXObject = new PdfImageXObject ( ImageDataFactory . Create ( SOURCE_FOLDER + "itis.jpg" ) ) ;
298
298
iText . Layout . Properties . BackgroundImage backgroundImage = new BackgroundImage . Builder ( ) . SetImage ( imageXObject
299
299
) . Build ( ) ;
300
- div . SetProperty ( Property . BACKGROUND_IMAGE , backgroundImage ) ;
300
+ div . SetBackgroundImage ( backgroundImage ) ;
301
301
doc . Add ( div ) ;
302
302
iText . Layout . Properties . BackgroundImage backgroundFormXObject = new BackgroundImage . Builder ( ) . SetImage ( CreateFormXObject
303
- ( pdfDocument ) ) . Build ( ) ;
303
+ ( pdfDocument , "itis.jpg" ) ) . Build ( ) ;
304
304
div = new Div ( ) . Add ( new Paragraph ( text + text + text ) ) ;
305
- div . SetProperty ( Property . BACKGROUND_IMAGE , backgroundFormXObject ) ;
305
+ div . SetBackgroundImage ( backgroundFormXObject ) ;
306
306
doc . Add ( div ) ;
307
307
pdfDocument . Close ( ) ;
308
308
NUnit . Framework . Assert . IsNull ( new CompareTool ( ) . CompareByContent ( outFileName , cmpFileName , DESTINATION_FOLDER
309
309
, "diff" ) ) ;
310
310
}
311
311
}
312
312
313
+ [ NUnit . Framework . Test ]
314
+ public virtual void BackgroundXFormObjectWithBboxTest ( ) {
315
+ // There shall be rock texture picture at the left top corner with 30pt width and 60pt height
316
+ String filename = "backgroundComplicatedXFormObjectTest" ;
317
+ String fileName = filename + ".pdf" ;
318
+ String outFileName = DESTINATION_FOLDER + fileName ;
319
+ String cmpFileName = SOURCE_FOLDER + "cmp_" + filename + ".pdf" ;
320
+ using ( PdfDocument pdfDocument = new PdfDocument ( new PdfWriter ( new FileStream ( outFileName , FileMode . Create
321
+ ) ) ) ) {
322
+ Document doc = new Document ( pdfDocument ) ;
323
+ String text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, " + "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "
324
+ + "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi " + "ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit "
325
+ + "in voluptate velit esse cillum dolore eu fugiat nulla pariatur. " + "Excepteur sint occaecat cupidatat non proident, sunt in culpa qui "
326
+ + "officia deserunt mollit anim id est laborum. " ;
327
+ iText . Layout . Properties . BackgroundImage backgroundFormXObject = new BackgroundImage . Builder ( ) . SetBackgroundRepeat
328
+ ( new BackgroundRepeat ( false , false ) ) . SetImage ( CreateFormXObject ( pdfDocument , "rock_texture.jpg" ) . SetBBox
329
+ ( new PdfArray ( new Rectangle ( 70 , - 15 , 50 , 75 ) ) ) ) . Build ( ) ;
330
+ Div div = new Div ( ) . Add ( new Paragraph ( text + text + text ) ) ;
331
+ div . SetBackgroundImage ( backgroundFormXObject ) ;
332
+ doc . Add ( div ) ;
333
+ pdfDocument . Close ( ) ;
334
+ NUnit . Framework . Assert . IsNull ( new CompareTool ( ) . CompareByContent ( outFileName , cmpFileName , DESTINATION_FOLDER
335
+ , "diff" ) ) ;
336
+ }
337
+ }
338
+
339
+ [ NUnit . Framework . Test ]
340
+ public virtual void BackgroundImageWithBboxTest ( ) {
341
+ // There shall be default rock texture picture with 100pt width and height at the left top corner. BBox shall not do any differences.
342
+ PdfImageXObject xObject = new PdfImageXObject ( ImageDataFactory . Create ( SOURCE_FOLDER + "rock_texture.jpg" ) )
343
+ . Put ( PdfName . BBox , new PdfArray ( new Rectangle ( 70 , - 15 , 500 , 750 ) ) ) ;
344
+ iText . Layout . Properties . BackgroundImage image = new BackgroundImage . Builder ( ) . SetImage ( xObject ) . SetBackgroundRepeat
345
+ ( new BackgroundRepeat ( false , false ) ) . Build ( ) ;
346
+ BackgroundImageGenericTest ( "backgroundImageWithBbox" , image ) ;
347
+ }
348
+
313
349
[ NUnit . Framework . Test ]
314
350
public virtual void BackgroundImageWithLinearGradientAndNormalBlendModeTest ( ) {
315
351
BlendModeTest ( BlendMode . NORMAL ) ;
@@ -406,8 +442,8 @@ private void BlendModeTest(BlendMode blendMode) {
406
442
( ) . GetValue ( ) , JavaUtil . ArraysAsList ( topBackgroundImage , backgroundImage ) ) ;
407
443
}
408
444
409
- private PdfFormXObject CreateFormXObject ( PdfDocument pdfDocument ) {
410
- ImageData image = ImageDataFactory . Create ( SOURCE_FOLDER + "itis.jpg" ) ;
445
+ private PdfFormXObject CreateFormXObject ( PdfDocument pdfDocument , String pictureName ) {
446
+ ImageData image = ImageDataFactory . Create ( SOURCE_FOLDER + pictureName ) ;
411
447
PdfFormXObject template = new PdfFormXObject ( new Rectangle ( image . GetWidth ( ) , image . GetHeight ( ) ) ) ;
412
448
PdfCanvas canvas = new PdfCanvas ( template , pdfDocument ) ;
413
449
canvas . AddImage ( image , 0 , 0 , image . GetWidth ( ) , false ) . Flush ( ) ;
@@ -443,7 +479,12 @@ private void BackgroundImageGenericTest(String filename, Object backgroundImage,
443
479
if ( angle != null ) {
444
480
div . SetRotationAngle ( angle . Value ) ;
445
481
}
446
- div . SetProperty ( Property . BACKGROUND_IMAGE , backgroundImage ) ;
482
+ if ( backgroundImage is iText . Layout . Properties . BackgroundImage ) {
483
+ div . SetBackgroundImage ( ( iText . Layout . Properties . BackgroundImage ) backgroundImage ) ;
484
+ }
485
+ else {
486
+ div . SetBackgroundImage ( ( IList < iText . Layout . Properties . BackgroundImage > ) backgroundImage ) ;
487
+ }
447
488
doc . Add ( div ) ;
448
489
pdfDocument . Close ( ) ;
449
490
NUnit . Framework . Assert . IsNull ( new CompareTool ( ) . CompareByContent ( outFileName , cmpFileName , DESTINATION_FOLDER
0 commit comments