//create a new workbook Workbook workbook = new Workbook(); IWorksheet sheet = workbook.getWorksheets().get(0); try { // Get stream of picture InputStream stream1 = this.getResourceStream("logo.png"); // Add a rectangle IShape rectangle = sheet.getShapes().addShape(AutoShapeType.Rectangle, 20, 20, 250, 50); // Set picture fill rectangle.getFill().userPicture(stream1, ImageType.PNG); rectangle.getLine().setTransparency(1); // Get stream of picture InputStream stream2 = this.getResourceStream("logo.png"); // Add a oval IShape oval = sheet.getShapes().addShape(AutoShapeType.Oval, 20, 90, 250, 50); // Set picture fill oval.getFill().userPicture(stream2, ImageType.PNG); oval.getLine().getColor().setRGB(Color.FromArgb(0x49129E)); } catch (IOException e) { e.printStackTrace(); } // Add a five point star IShape star = sheet.getShapes().addShape(AutoShapeType.Shape5pointStar, 300, 20, 100, 100); // Set picture fill star.getFill().presetTextured(PresetTexture.WaterDroplets); //save to an pdf file workbook.save("ShapeWithPictureOrTextureFill.pdf");
//create a new workbook var workbook = Workbook() val sheet = workbook.worksheets.get(0) try { // Get stream of picture val stream1 = this.getResourceStream("logo.png") // Add a rectangle val rectangle = sheet.shapes.addShape(AutoShapeType.Rectangle, 20.0, 20.0, 250.0, 50.0) // Set picture fill rectangle.fill.userPicture(stream1, ImageType.PNG) rectangle.line.transparency = 1.0 // Get stream of picture val stream2 = this.getResourceStream("logo.png") // Add a oval val oval = sheet.shapes.addShape(AutoShapeType.Oval, 20.0, 90.0, 250.0, 50.0) // Set picture fill oval.fill.userPicture(stream2, ImageType.PNG) oval.line.color.rgb = Color.FromArgb(0x49129E) } catch (e: IOException) { e.printStackTrace() } // Add a five point star val star = sheet.shapes.addShape(AutoShapeType.Shape5pointStar, 300.0, 20.0, 100.0, 100.0) // Set picture fill star.fill.presetTextured(PresetTexture.WaterDroplets) //save to an pdf file workbook.save("ShapeWithPictureOrTextureFill.pdf")