BackgroundImage { public BackgroundSize getBackgroundSize() { return backgroundSize; } BackgroundImage(BackgroundImage backgroundImage); @Deprecated  BackgroundImage(final PdfImageXObject image, final BackgroundRepeat repeat, final BlendMode blendMode); @Deprecated  BackgroundImage(final PdfFormXObject image, final BackgroundRepeat repeat, final BlendMode blendMode); @Deprecated  BackgroundImage(final PdfImageXObject image, final BackgroundRepeat repeat); @Deprecated  BackgroundImage(final PdfFormXObject image, final BackgroundRepeat repeat); @Deprecated  BackgroundImage(final PdfImageXObject image); @Deprecated  BackgroundImage(final PdfFormXObject image); @Deprecated  BackgroundImage(final PdfImageXObject image, final boolean repeatX, final boolean repeatY); @Deprecated  BackgroundImage(final PdfFormXObject image, final boolean repeatX, final boolean repeatY); @Deprecated  BackgroundImage(final AbstractLinearGradientBuilder linearGradientBuilder); @Deprecated  BackgroundImage(final AbstractLinearGradientBuilder linearGradientBuilder, final BlendMode blendMode); private  BackgroundImage(PdfXObject image, BackgroundRepeat repeat, BackgroundPosition position,
            BackgroundSize backgroundSize, AbstractLinearGradientBuilder linearGradientBuilder,
            BlendMode blendMode, BackgroundBox clip, BackgroundBox origin); PdfImageXObject getImage(); PdfFormXObject getForm(); BackgroundPosition getBackgroundPosition(); AbstractLinearGradientBuilder getLinearGradientBuilder(); boolean isBackgroundSpecified(); @Deprecated boolean isRepeatX(); @Deprecated boolean isRepeatY(); BackgroundSize getBackgroundSize(); float getImageWidth(); float getImageHeight(); @Deprecated float getWidth(); @Deprecated float getHeight(); BackgroundRepeat getRepeat(); BlendMode getBlendMode(); BackgroundBox getBackgroundClip(); BackgroundBox getBackgroundOrigin();  }
@Test public void backgroundImageWithPercentWidth() throws IOException, InterruptedException { PdfImageXObject xObject = new PdfImageXObject(ImageDataFactory.create(SOURCE_FOLDER + "pattern-grg-rrg-rgg.png")); BackgroundImage backgroundImage = new BackgroundImage.Builder().setImage(xObject).build(); String outFileName = DESTINATION_FOLDER + "backgroundImageWithPercentWidth.pdf"; String cmpFileName = SOURCE_FOLDER + "cmp_backgroundImageWithPercentWidth.pdf"; try (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(new FileOutputStream(outFileName)))) { Document doc = new Document(pdfDocument); Text textElement = new Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, " + "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "); textElement.setFontSize(50); backgroundImage.getBackgroundSize().setBackgroundSizeToValues(UnitValue.createPercentValue(30), null); textElement.setProperty(Property.BACKGROUND_IMAGE, backgroundImage); doc.add(new Paragraph(textElement)); } Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, DESTINATION_FOLDER, "diff")); }
@Test public void backgroundImageWithPercentHeight() throws IOException, InterruptedException { PdfImageXObject xObject = new PdfImageXObject(ImageDataFactory.create(SOURCE_FOLDER + "pattern-grg-rrg-rgg.png")); BackgroundImage backgroundImage = new BackgroundImage.Builder().setImage(xObject).build(); String outFileName = DESTINATION_FOLDER + "backgroundImageWithPercentHeight.pdf"; String cmpFileName = SOURCE_FOLDER + "cmp_backgroundImageWithPercentHeight.pdf"; try (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(new FileOutputStream(outFileName)))) { Document doc = new Document(pdfDocument); Text textElement = new Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, " + "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "); textElement.setFontSize(50); backgroundImage.getBackgroundSize().setBackgroundSizeToValues(null, UnitValue.createPercentValue(30)); textElement.setProperty(Property.BACKGROUND_IMAGE, backgroundImage); doc.add(new Paragraph(textElement)); } Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, DESTINATION_FOLDER, "diff")); }
@Test public void backgroundImageWithPercentHeightAndWidth() throws IOException, InterruptedException { PdfImageXObject xObject = new PdfImageXObject(ImageDataFactory.create(SOURCE_FOLDER + "pattern-grg-rrg-rgg.png")); BackgroundImage backgroundImage = new BackgroundImage.Builder().setImage(xObject).build(); String outFileName = DESTINATION_FOLDER + "backgroundImageWithPercentHeightAndWidth.pdf"; String cmpFileName = SOURCE_FOLDER + "cmp_backgroundImageWithPercentHeightAndWidth.pdf"; try (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(new FileOutputStream(outFileName)))) { Document doc = new Document(pdfDocument); Text textElement = new Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, " + "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "); textElement.setFontSize(50); backgroundImage.getBackgroundSize().setBackgroundSizeToValues(UnitValue.createPercentValue(20), UnitValue.createPercentValue(20)); textElement.setProperty(Property.BACKGROUND_IMAGE, backgroundImage); doc.add(new Paragraph(textElement)); } Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, DESTINATION_FOLDER, "diff")); }
@Test public void backgroundImageWithPointWidth() throws IOException, InterruptedException { PdfImageXObject xObject = new PdfImageXObject(ImageDataFactory.create(SOURCE_FOLDER + "pattern-grg-rrg-rgg.png")); BackgroundImage backgroundImage = new BackgroundImage.Builder().setImage(xObject).build(); String outFileName = DESTINATION_FOLDER + "backgroundImageWithPointWidth.pdf"; String cmpFileName = SOURCE_FOLDER + "cmp_backgroundImageWithPointWidth.pdf"; try (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(new FileOutputStream(outFileName)))) { Document doc = new Document(pdfDocument); Text textElement = new Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, " + "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "); textElement.setFontSize(50); backgroundImage.getBackgroundSize().setBackgroundSizeToValues(UnitValue.createPointValue(15), null); textElement.setProperty(Property.BACKGROUND_IMAGE, backgroundImage); doc.add(new Paragraph(textElement)); } Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, DESTINATION_FOLDER, "diff")); }
@Test public void backgroundImageWithPointHeight() throws IOException, InterruptedException { PdfImageXObject xObject = new PdfImageXObject(ImageDataFactory.create(SOURCE_FOLDER + "pattern-grg-rrg-rgg.png")); BackgroundImage backgroundImage = new BackgroundImage.Builder().setImage(xObject).build(); String outFileName = DESTINATION_FOLDER + "backgroundImageWithPointHeight.pdf"; String cmpFileName = SOURCE_FOLDER + "cmp_backgroundImageWithPointHeight.pdf"; try (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(new FileOutputStream(outFileName)))) { Document doc = new Document(pdfDocument); Text textElement = new Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, " + "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "); textElement.setFontSize(50); backgroundImage.getBackgroundSize().setBackgroundSizeToValues(null, UnitValue.createPointValue(20)); textElement.setProperty(Property.BACKGROUND_IMAGE, backgroundImage); doc.add(new Paragraph(textElement)); } Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, DESTINATION_FOLDER, "diff")); }
@Test public void backgroundImageWithPointHeightAndWidth() throws IOException, InterruptedException { PdfImageXObject xObject = new PdfImageXObject(ImageDataFactory.create(SOURCE_FOLDER + "pattern-grg-rrg-rgg.png")); BackgroundImage backgroundImage = new BackgroundImage.Builder().setImage(xObject).build(); String outFileName = DESTINATION_FOLDER + "backgroundImageWithPointHeightAndWidth.pdf"; String cmpFileName = SOURCE_FOLDER + "cmp_backgroundImageWithPointHeightAndWidth.pdf"; try (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(new FileOutputStream(outFileName)))) { Document doc = new Document(pdfDocument); Text textElement = new Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, " + "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "); textElement.setFontSize(50); backgroundImage.getBackgroundSize().setBackgroundSizeToValues(UnitValue.createPointValue(50), UnitValue.createPointValue(100)); textElement.setProperty(Property.BACKGROUND_IMAGE, backgroundImage); doc.add(new Paragraph(textElement)); } Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, DESTINATION_FOLDER, "diff")); }
@Test public void backgroundImageWithLowWidthAndHeight() throws IOException, InterruptedException { PdfImageXObject xObject = new PdfImageXObject(ImageDataFactory.create(SOURCE_FOLDER + "pattern-grg-rrg-rgg.png")); BackgroundImage backgroundImage = new BackgroundImage.Builder().setImage(xObject).build(); String outFileName = DESTINATION_FOLDER + "backgroundImageWithLowWidthAndHeight.pdf"; String cmpFileName = SOURCE_FOLDER + "cmp_backgroundImageWithLowWidthAndHeight.pdf"; try (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(new FileOutputStream(outFileName)))) { Document doc = new Document(pdfDocument); Text textElement = new Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, " + "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "); textElement.setFontSize(50); backgroundImage.getBackgroundSize().setBackgroundSizeToValues(UnitValue.createPointValue(-1), UnitValue.createPointValue(-1)); textElement.setProperty(Property.BACKGROUND_IMAGE, backgroundImage); doc.add(new Paragraph(textElement)); } Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, DESTINATION_FOLDER, "diff")); }