@@ -167,6 +167,170 @@ public virtual void BackgroundImageForText() {
167
167
, "diff" ) ) ;
168
168
}
169
169
170
+ [ NUnit . Framework . Test ]
171
+ public virtual void BackgroundImageWithPercentWidth ( ) {
172
+ //TODO DEVSIX-4370 first pixel near the border is redrawn by another image
173
+ PdfImageXObject xObject = new PdfImageXObject ( ImageDataFactory . Create ( SOURCE_FOLDER + "pattern-grg-rrg-rgg.png"
174
+ ) ) ;
175
+ iText . Layout . Properties . BackgroundImage backgroundImage = new BackgroundImage . Builder ( ) . SetImage ( xObject ) .
176
+ Build ( ) ;
177
+ String outFileName = DESTINATION_FOLDER + "backgroundImageWithPercentWidth.pdf" ;
178
+ String cmpFileName = SOURCE_FOLDER + "cmp_backgroundImageWithPercentWidth.pdf" ;
179
+ using ( PdfDocument pdfDocument = new PdfDocument ( new PdfWriter ( new FileStream ( outFileName , FileMode . Create
180
+ ) ) ) ) {
181
+ Document doc = new Document ( pdfDocument ) ;
182
+ Text textElement = new Text ( "Lorem ipsum dolor sit amet, consectetur adipiscing elit, " + "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "
183
+ ) ;
184
+ textElement . SetFontSize ( 50 ) ;
185
+ backgroundImage . GetBackgroundSize ( ) . SetBackgroundSizeToValues ( UnitValue . CreatePercentValue ( 30 ) , null ) ;
186
+ textElement . SetProperty ( Property . BACKGROUND_IMAGE , backgroundImage ) ;
187
+ doc . Add ( new Paragraph ( textElement ) ) ;
188
+ }
189
+ NUnit . Framework . Assert . IsNull ( new CompareTool ( ) . CompareByContent ( outFileName , cmpFileName , DESTINATION_FOLDER
190
+ , "diff" ) ) ;
191
+ }
192
+
193
+ [ NUnit . Framework . Test ]
194
+ public virtual void BackgroundImageWithPercentHeight ( ) {
195
+ //TODO DEVSIX-4370 first pixel near the border is redrawn by another image
196
+ PdfImageXObject xObject = new PdfImageXObject ( ImageDataFactory . Create ( SOURCE_FOLDER + "pattern-grg-rrg-rgg.png"
197
+ ) ) ;
198
+ iText . Layout . Properties . BackgroundImage backgroundImage = new BackgroundImage . Builder ( ) . SetImage ( xObject ) .
199
+ Build ( ) ;
200
+ String outFileName = DESTINATION_FOLDER + "backgroundImageWithPercentHeight.pdf" ;
201
+ String cmpFileName = SOURCE_FOLDER + "cmp_backgroundImageWithPercentHeight.pdf" ;
202
+ using ( PdfDocument pdfDocument = new PdfDocument ( new PdfWriter ( new FileStream ( outFileName , FileMode . Create
203
+ ) ) ) ) {
204
+ Document doc = new Document ( pdfDocument ) ;
205
+ Text textElement = new Text ( "Lorem ipsum dolor sit amet, consectetur adipiscing elit, " + "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "
206
+ ) ;
207
+ textElement . SetFontSize ( 50 ) ;
208
+ backgroundImage . GetBackgroundSize ( ) . SetBackgroundSizeToValues ( null , UnitValue . CreatePercentValue ( 30 ) ) ;
209
+ textElement . SetProperty ( Property . BACKGROUND_IMAGE , backgroundImage ) ;
210
+ doc . Add ( new Paragraph ( textElement ) ) ;
211
+ }
212
+ NUnit . Framework . Assert . IsNull ( new CompareTool ( ) . CompareByContent ( outFileName , cmpFileName , DESTINATION_FOLDER
213
+ , "diff" ) ) ;
214
+ }
215
+
216
+ [ NUnit . Framework . Test ]
217
+ public virtual void BackgroundImageWithPercentHeightAndWidth ( ) {
218
+ //TODO DEVSIX-4370 first pixel near the border is redrawn by another image
219
+ PdfImageXObject xObject = new PdfImageXObject ( ImageDataFactory . Create ( SOURCE_FOLDER + "pattern-grg-rrg-rgg.png"
220
+ ) ) ;
221
+ iText . Layout . Properties . BackgroundImage backgroundImage = new BackgroundImage . Builder ( ) . SetImage ( xObject ) .
222
+ Build ( ) ;
223
+ String outFileName = DESTINATION_FOLDER + "backgroundImageWithPercentHeightAndWidth.pdf" ;
224
+ String cmpFileName = SOURCE_FOLDER + "cmp_backgroundImageWithPercentHeightAndWidth.pdf" ;
225
+ using ( PdfDocument pdfDocument = new PdfDocument ( new PdfWriter ( new FileStream ( outFileName , FileMode . Create
226
+ ) ) ) ) {
227
+ Document doc = new Document ( pdfDocument ) ;
228
+ Text textElement = new Text ( "Lorem ipsum dolor sit amet, consectetur adipiscing elit, " + "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "
229
+ ) ;
230
+ textElement . SetFontSize ( 50 ) ;
231
+ backgroundImage . GetBackgroundSize ( ) . SetBackgroundSizeToValues ( UnitValue . CreatePercentValue ( 20 ) , UnitValue .
232
+ CreatePercentValue ( 20 ) ) ;
233
+ textElement . SetProperty ( Property . BACKGROUND_IMAGE , backgroundImage ) ;
234
+ doc . Add ( new Paragraph ( textElement ) ) ;
235
+ }
236
+ NUnit . Framework . Assert . IsNull ( new CompareTool ( ) . CompareByContent ( outFileName , cmpFileName , DESTINATION_FOLDER
237
+ , "diff" ) ) ;
238
+ }
239
+
240
+ [ NUnit . Framework . Test ]
241
+ public virtual void BackgroundImageWithPointWidth ( ) {
242
+ //TODO DEVSIX-4370 first pixel near the border is redrawn by another image
243
+ PdfImageXObject xObject = new PdfImageXObject ( ImageDataFactory . Create ( SOURCE_FOLDER + "pattern-grg-rrg-rgg.png"
244
+ ) ) ;
245
+ iText . Layout . Properties . BackgroundImage backgroundImage = new BackgroundImage . Builder ( ) . SetImage ( xObject ) .
246
+ Build ( ) ;
247
+ String outFileName = DESTINATION_FOLDER + "backgroundImageWithPointWidth.pdf" ;
248
+ String cmpFileName = SOURCE_FOLDER + "cmp_backgroundImageWithPointWidth.pdf" ;
249
+ using ( PdfDocument pdfDocument = new PdfDocument ( new PdfWriter ( new FileStream ( outFileName , FileMode . Create
250
+ ) ) ) ) {
251
+ Document doc = new Document ( pdfDocument ) ;
252
+ Text textElement = new Text ( "Lorem ipsum dolor sit amet, consectetur adipiscing elit, " + "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "
253
+ ) ;
254
+ textElement . SetFontSize ( 50 ) ;
255
+ backgroundImage . GetBackgroundSize ( ) . SetBackgroundSizeToValues ( UnitValue . CreatePointValue ( 15 ) , null ) ;
256
+ textElement . SetProperty ( Property . BACKGROUND_IMAGE , backgroundImage ) ;
257
+ doc . Add ( new Paragraph ( textElement ) ) ;
258
+ }
259
+ NUnit . Framework . Assert . IsNull ( new CompareTool ( ) . CompareByContent ( outFileName , cmpFileName , DESTINATION_FOLDER
260
+ , "diff" ) ) ;
261
+ }
262
+
263
+ [ NUnit . Framework . Test ]
264
+ public virtual void BackgroundImageWithPointHeight ( ) {
265
+ //TODO DEVSIX-4370 first pixel near the border is redrawn by another image
266
+ PdfImageXObject xObject = new PdfImageXObject ( ImageDataFactory . Create ( SOURCE_FOLDER + "pattern-grg-rrg-rgg.png"
267
+ ) ) ;
268
+ iText . Layout . Properties . BackgroundImage backgroundImage = new BackgroundImage . Builder ( ) . SetImage ( xObject ) .
269
+ Build ( ) ;
270
+ String outFileName = DESTINATION_FOLDER + "backgroundImageWithPointHeight.pdf" ;
271
+ String cmpFileName = SOURCE_FOLDER + "cmp_backgroundImageWithPointHeight.pdf" ;
272
+ using ( PdfDocument pdfDocument = new PdfDocument ( new PdfWriter ( new FileStream ( outFileName , FileMode . Create
273
+ ) ) ) ) {
274
+ Document doc = new Document ( pdfDocument ) ;
275
+ Text textElement = new Text ( "Lorem ipsum dolor sit amet, consectetur adipiscing elit, " + "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "
276
+ ) ;
277
+ textElement . SetFontSize ( 50 ) ;
278
+ backgroundImage . GetBackgroundSize ( ) . SetBackgroundSizeToValues ( null , UnitValue . CreatePointValue ( 20 ) ) ;
279
+ textElement . SetProperty ( Property . BACKGROUND_IMAGE , backgroundImage ) ;
280
+ doc . Add ( new Paragraph ( textElement ) ) ;
281
+ }
282
+ NUnit . Framework . Assert . IsNull ( new CompareTool ( ) . CompareByContent ( outFileName , cmpFileName , DESTINATION_FOLDER
283
+ , "diff" ) ) ;
284
+ }
285
+
286
+ [ NUnit . Framework . Test ]
287
+ public virtual void BackgroundImageWithPointHeightAndWidth ( ) {
288
+ //TODO DEVSIX-4370 first pixel near the border is redrawn by another image
289
+ PdfImageXObject xObject = new PdfImageXObject ( ImageDataFactory . Create ( SOURCE_FOLDER + "pattern-grg-rrg-rgg.png"
290
+ ) ) ;
291
+ iText . Layout . Properties . BackgroundImage backgroundImage = new BackgroundImage . Builder ( ) . SetImage ( xObject ) .
292
+ Build ( ) ;
293
+ String outFileName = DESTINATION_FOLDER + "backgroundImageWithPointHeightAndWidth.pdf" ;
294
+ String cmpFileName = SOURCE_FOLDER + "cmp_backgroundImageWithPointHeightAndWidth.pdf" ;
295
+ using ( PdfDocument pdfDocument = new PdfDocument ( new PdfWriter ( new FileStream ( outFileName , FileMode . Create
296
+ ) ) ) ) {
297
+ Document doc = new Document ( pdfDocument ) ;
298
+ Text textElement = new Text ( "Lorem ipsum dolor sit amet, consectetur adipiscing elit, " + "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "
299
+ ) ;
300
+ textElement . SetFontSize ( 50 ) ;
301
+ backgroundImage . GetBackgroundSize ( ) . SetBackgroundSizeToValues ( UnitValue . CreatePointValue ( 50 ) , UnitValue . CreatePointValue
302
+ ( 100 ) ) ;
303
+ textElement . SetProperty ( Property . BACKGROUND_IMAGE , backgroundImage ) ;
304
+ doc . Add ( new Paragraph ( textElement ) ) ;
305
+ }
306
+ NUnit . Framework . Assert . IsNull ( new CompareTool ( ) . CompareByContent ( outFileName , cmpFileName , DESTINATION_FOLDER
307
+ , "diff" ) ) ;
308
+ }
309
+
310
+ [ NUnit . Framework . Test ]
311
+ public virtual void BackgroundImageWithLowWidthAndHeight ( ) {
312
+ //TODO DEVSIX-4370 first pixel near the border is redrawn by another image
313
+ PdfImageXObject xObject = new PdfImageXObject ( ImageDataFactory . Create ( SOURCE_FOLDER + "pattern-grg-rrg-rgg.png"
314
+ ) ) ;
315
+ iText . Layout . Properties . BackgroundImage backgroundImage = new BackgroundImage . Builder ( ) . SetImage ( xObject ) .
316
+ Build ( ) ;
317
+ String outFileName = DESTINATION_FOLDER + "backgroundImageWithLowWidthAndHeight.pdf" ;
318
+ String cmpFileName = SOURCE_FOLDER + "cmp_backgroundImageWithLowWidthAndHeight.pdf" ;
319
+ using ( PdfDocument pdfDocument = new PdfDocument ( new PdfWriter ( new FileStream ( outFileName , FileMode . Create
320
+ ) ) ) ) {
321
+ Document doc = new Document ( pdfDocument ) ;
322
+ Text textElement = new Text ( "Lorem ipsum dolor sit amet, consectetur adipiscing elit, " + "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "
323
+ ) ;
324
+ textElement . SetFontSize ( 50 ) ;
325
+ backgroundImage . GetBackgroundSize ( ) . SetBackgroundSizeToValues ( UnitValue . CreatePointValue ( - 1 ) , UnitValue . CreatePointValue
326
+ ( - 1 ) ) ;
327
+ textElement . SetProperty ( Property . BACKGROUND_IMAGE , backgroundImage ) ;
328
+ doc . Add ( new Paragraph ( textElement ) ) ;
329
+ }
330
+ NUnit . Framework . Assert . IsNull ( new CompareTool ( ) . CompareByContent ( outFileName , cmpFileName , DESTINATION_FOLDER
331
+ , "diff" ) ) ;
332
+ }
333
+
170
334
[ NUnit . Framework . Test ]
171
335
public virtual void BackgroundImageWithoutRepeatXTest ( ) {
172
336
PdfImageXObject xObject = new PdfImageXObject ( ImageDataFactory . Create ( SOURCE_FOLDER + "itis.jpg" ) ) ;
0 commit comments