List of usage examples for org.apache.pdfbox.pdmodel PDPageContentStream PDPageContentStream
public PDPageContentStream(PDDocument doc, PDAppearanceStream appearance, OutputStream outputStream)
From source file:de.rototor.pdfbox.graphics2d.PdfBoxGraphics2D.java
License:Apache License
PdfBoxGraphics2D(PDDocument document, PDRectangle bbox, PdfBoxGraphics2D parentGfx) throws IOException { this.document = document; this.bbox = bbox; PDAppearanceStream appearance = new PDAppearanceStream(document); xFormObject = appearance;//from w w w .ja v a 2s . c o m xFormObject.setResources(new PDResources()); xFormObject.setBBox(bbox); contentStream = new PDPageContentStream(document, appearance, xFormObject.getStream().createOutputStream(COSName.FLATE_DECODE)); contentStreamSaveState(); if (parentGfx != null) { this.colorMapper = parentGfx.colorMapper; this.fontTextDrawer = parentGfx.fontTextDrawer; this.imageEncoder = parentGfx.imageEncoder; this.paintApplier = parentGfx.paintApplier; } baseTransform = new AffineTransform(); baseTransform.translate(0, bbox.getHeight()); baseTransform.scale(1, -1); calcImage = new BufferedImage(100, 100, BufferedImage.TYPE_4BYTE_ABGR); calcGfx = calcImage.createGraphics(); font = calcGfx.getFont(); copyInfo = null; }
From source file:de.rototor.pdfbox.graphics2d.PdfBoxGraphics2D.java
License:Apache License
private void applyShadingAsColor(PDShading shading) throws IOException { /*/* www . j a v a 2 s. c o m*/ * If the paint has a shading we must create a tiling pattern and set that as * stroke color... */ PDTilingPattern pattern = new PDTilingPattern(); pattern.setPaintType(PDTilingPattern.PAINT_COLORED); pattern.setTilingType(PDTilingPattern.TILING_CONSTANT_SPACING_FASTER_TILING); PDRectangle anchorRect = bbox; pattern.setBBox(anchorRect); pattern.setXStep(anchorRect.getWidth()); pattern.setYStep(anchorRect.getHeight()); PDAppearanceStream appearance = new PDAppearanceStream(this.document); appearance.setResources(pattern.getResources()); appearance.setBBox(pattern.getBBox()); PDPageContentStream imageContentStream = new PDPageContentStream(document, appearance, ((COSStream) pattern.getCOSObject()).createOutputStream()); imageContentStream.addRect(0, 0, anchorRect.getWidth(), anchorRect.getHeight()); imageContentStream.clip(); imageContentStream.shadingFill(shading); imageContentStream.close(); PDColorSpace patternCS1 = new PDPattern(null); COSName tilingPatternName = xFormObject.getResources().add(pattern); PDColor patternColor = new PDColor(tilingPatternName, patternCS1); contentStream.setNonStrokingColor(patternColor); contentStream.setStrokingColor(patternColor); }