PdfCanvas implements Serializable { @Deprecated public PdfXObject addImage(ImageData image, float a, float b, float c, float d, float e, float f) { return addImageWithTransformationMatrix(image, a, b, c, d, e, f); } PdfCanvas(PdfStream contentStream, PdfResources resources, PdfDocument document);  PdfCanvas(PdfPage page);  PdfCanvas(PdfPage page, boolean wrapOldContent);  PdfCanvas(PdfFormXObject xObj, PdfDocument document);  PdfCanvas(PdfDocument doc, int pageNum); PdfResources getResources(); PdfDocument getDocument(); void attachContentStream(PdfStream contentStream); CanvasGraphicsState getGraphicsState(); void release(); PdfCanvas saveState(); PdfCanvas restoreState(); PdfCanvas concatMatrix(double a, double b, double c, double d, double e, double f); PdfCanvas concatMatrix(PdfArray array); PdfCanvas concatMatrix(AffineTransform transform); PdfCanvas beginText(); PdfCanvas endText(); PdfCanvas beginVariableText(); PdfCanvas endVariableText(); PdfCanvas setFontAndSize(PdfFont font, float size); PdfCanvas moveText(double x, double y); PdfCanvas setLeading(float leading); PdfCanvas moveTextWithLeading(float x, float y); PdfCanvas newlineText(); PdfCanvas newlineShowText(String text); PdfCanvas newlineShowText(float wordSpacing, float charSpacing, String text); PdfCanvas setTextRenderingMode(int textRenderingMode); PdfCanvas setTextRise(float textRise); PdfCanvas setWordSpacing(float wordSpacing); PdfCanvas setCharacterSpacing(float charSpacing); PdfCanvas setHorizontalScaling(float scale); PdfCanvas setTextMatrix(float a, float b, float c, float d, float x, float y); PdfCanvas setTextMatrix(AffineTransform transform); PdfCanvas setTextMatrix(float x, float y); PdfCanvas showText(String text); PdfCanvas showText(GlyphLine text); PdfCanvas showText(GlyphLine text, Iterator<GlyphLine.GlyphLinePart> iterator); PdfCanvas showText(PdfArray textArray); PdfCanvas moveTo(double x, double y); PdfCanvas lineTo(double x, double y); PdfCanvas curveTo(double x1, double y1, double x2, double y2, double x3, double y3); PdfCanvas curveTo(double x2, double y2, double x3, double y3); PdfCanvas curveFromTo(double x1, double y1, double x3, double y3); PdfCanvas arc(double x1, double y1, double x2, double y2,
                         double startAng, double extent); PdfCanvas ellipse(double x1, double y1, double x2, double y2); static List<double[]> bezierArc(double x1, double y1, double x2, double y2, double startAng, double extent); PdfCanvas rectangle(double x, double y, double width, double height); PdfCanvas rectangle(Rectangle rectangle); PdfCanvas roundRectangle(double x, double y, double width, double height, double radius); PdfCanvas circle(double x, double y, double r); PdfCanvas paintShading(PdfShading shading); PdfCanvas closePath(); PdfCanvas closePathEoFillStroke(); PdfCanvas closePathFillStroke(); @Deprecated PdfCanvas newPath(); PdfCanvas endPath(); PdfCanvas stroke(); PdfCanvas clip(); PdfCanvas eoClip(); PdfCanvas closePathStroke(); PdfCanvas fill(); PdfCanvas fillStroke(); PdfCanvas eoFill(); PdfCanvas eoFillStroke(); PdfCanvas setLineWidth(float lineWidth); PdfCanvas setLineCapStyle(int lineCapStyle); PdfCanvas setLineJoinStyle(int lineJoinStyle); PdfCanvas setMiterLimit(float miterLimit); PdfCanvas setLineDash(float phase); PdfCanvas setLineDash(float unitsOn, float phase); PdfCanvas setLineDash(float unitsOn, float unitsOff, float phase); PdfCanvas setLineDash(float[] array, float phase); PdfCanvas setRenderingIntent(PdfName renderingIntent); PdfCanvas setFlatnessTolerance(float flatnessTolerance); PdfCanvas setFillColor(Color color); PdfCanvas setStrokeColor(Color color); PdfCanvas setColor(Color color, boolean fill); PdfCanvas setColor(PdfColorSpace colorSpace, float[] colorValue, boolean fill); PdfCanvas setColor(PdfColorSpace colorSpace, float[] colorValue, PdfPattern pattern, boolean fill); PdfCanvas setFillColorGray(float g); PdfCanvas setStrokeColorGray(float g); PdfCanvas resetFillColorGray(); PdfCanvas resetStrokeColorGray(); PdfCanvas setFillColorRgb(float r, float g, float b); PdfCanvas setStrokeColorRgb(float r, float g, float b); PdfCanvas setFillColorShading(PdfPattern.Shading shading); PdfCanvas setStrokeColorShading(PdfPattern.Shading shading); PdfCanvas resetFillColorRgb(); PdfCanvas resetStrokeColorRgb(); PdfCanvas setFillColorCmyk(float c, float m, float y, float k); PdfCanvas setStrokeColorCmyk(float c, float m, float y, float k); PdfCanvas resetFillColorCmyk(); PdfCanvas resetStrokeColorCmyk(); PdfCanvas beginLayer(IPdfOCG layer); PdfCanvas endLayer(); @Deprecated PdfXObject addImage(ImageData image, float a, float b, float c, float d, float e, float f); PdfXObject addImageWithTransformationMatrix(ImageData image, float a, float b, float c, float d, float e, float f); @Deprecated PdfXObject addImage(ImageData image, float a, float b, float c, float d, float e, float f, boolean asInline); PdfXObject addImageWithTransformationMatrix(ImageData image, float a, float b, float c, float d, float e, float f, boolean asInline); @Deprecated PdfXObject addImage(ImageData image, Rectangle rect, boolean asInline); PdfXObject addImageFittedIntoRectangle(ImageData image, Rectangle rect, boolean asInline); @Deprecated PdfXObject addImage(ImageData image, float x, float y, boolean asInline); PdfXObject addImageAt(ImageData image, float x, float y, boolean asInline); @Deprecated PdfXObject addImage(ImageData image, float x, float y, float width, boolean asInline); @Deprecated PdfXObject addImage(ImageData image, float x, float y, float height, boolean asInline, boolean dummy); PdfCanvas addXObjectWithTransformationMatrix(PdfXObject xObject, float a, float b, float c, float d, float e, float f); @Deprecated PdfCanvas addXObject(PdfXObject xObject, float a, float b, float c, float d, float e, float f); PdfCanvas addXObjectAt(PdfXObject xObject, float x, float y); @Deprecated PdfCanvas addXObject(PdfXObject xObject, float x, float y); PdfCanvas addXObjectFittedIntoRectangle(PdfXObject xObject, Rectangle rect); @Deprecated PdfCanvas addXObject(PdfXObject xObject, Rectangle rect); @Deprecated PdfCanvas addXObject(PdfXObject xObject, float x, float y, float width); @Deprecated PdfCanvas addXObject(PdfXObject xObject, float x, float y, float height, boolean dummy); PdfCanvas addXObject(PdfXObject xObject); PdfCanvas setExtGState(PdfExtGState extGState); PdfExtGState setExtGState(PdfDictionary extGState); PdfCanvas beginMarkedContent(PdfName tag); PdfCanvas beginMarkedContent(PdfName tag, PdfDictionary properties); PdfCanvas endMarkedContent(); PdfCanvas openTag(CanvasTag tag); PdfCanvas openTag(TagReference tagReference); PdfCanvas closeTag(); PdfCanvas writeLiteral(String s); PdfCanvas writeLiteral(char c); PdfCanvas writeLiteral(float n); PdfStream getContentStream();  }
@Test public void wmfImageTest01() throws IOException, InterruptedException { PdfDocument document = new PdfDocument(new PdfWriter(destinationFolder + "wmfImageTest01.pdf")); PdfPage page = document.addNewPage(); PdfCanvas canvas = new PdfCanvas(page); ImageData img = new WmfImageData(sourceFolder + "example.wmf"); canvas.addImage(img, 0, 0, 0.1f, false); document.close(); Assert.assertNull(new CompareTool().compareByContent(destinationFolder + "wmfImageTest01.pdf", sourceFolder + "cmp_wmfImageTest01.pdf", destinationFolder, "diff_")); }
@Test public void wmfImageTest02() throws IOException, InterruptedException { PdfDocument document = new PdfDocument(new PdfWriter(destinationFolder + "wmfImageTest02.pdf")); PdfPage page = document.addNewPage(); PdfCanvas canvas = new PdfCanvas(page); ImageData img = new WmfImageData(sourceFolder + "butterfly.wmf"); canvas.addImage(img, 0, 0, 1, false); document.close(); Assert.assertNull(new CompareTool().compareByContent(destinationFolder + "wmfImageTest02.pdf", sourceFolder + "cmp_wmfImageTest02.pdf", destinationFolder, "diff_")); }
@Test public void wmfImageTest03() throws IOException, InterruptedException { PdfDocument document = new PdfDocument(new PdfWriter(destinationFolder + "wmfImageTest03.pdf")); PdfPage page = document.addNewPage(); PdfCanvas canvas = new PdfCanvas(page); ImageData img = new WmfImageData(sourceFolder + "type1.wmf"); canvas.addImage(img, 0, 0, 1, false); document.close(); Assert.assertNull(new CompareTool().compareByContent(destinationFolder + "wmfImageTest03.pdf", sourceFolder + "cmp_wmfImageTest03.pdf", destinationFolder, "diff_")); }
@Test public void wmfImageTest04() throws IOException, InterruptedException { PdfDocument document = new PdfDocument(new PdfWriter(destinationFolder + "wmfImageTest04.pdf")); PdfPage page = document.addNewPage(); PdfCanvas canvas = new PdfCanvas(page); ImageData img = new WmfImageData(sourceFolder + "type0.wmf"); canvas.addImage(img, 0, 0, 1, false); document.close(); Assert.assertNull(new CompareTool().compareByContent(destinationFolder + "wmfImageTest04.pdf", sourceFolder + "cmp_wmfImageTest04.pdf", destinationFolder, "diff_")); }
@Test public void wmfImageTest05() throws IOException, InterruptedException { PdfDocument document = new PdfDocument(new PdfWriter(destinationFolder + "wmfImageTest05.pdf")); PdfPage page = document.addNewPage(); PdfCanvas canvas = new PdfCanvas(page); InputStream stream = UrlUtil.openStream(UrlUtil.toURL(sourceFolder + "example2.wmf")); ByteArrayOutputStream baos = new ByteArrayOutputStream(); StreamUtil.transferBytes(stream, baos); ImageData img = new WmfImageData(baos.toByteArray()); canvas.addImage(img, 0, 0, 1, false); document.close(); Assert.assertNull(new CompareTool().compareByContent(destinationFolder + "wmfImageTest05.pdf", sourceFolder + "cmp_wmfImageTest05.pdf", destinationFolder, "diff_")); }
@Test public void gifImageTest01() throws IOException, InterruptedException { PdfDocument document = new PdfDocument(new PdfWriter(destinationFolder + "gifImageTest01.pdf")); PdfPage page = document.addNewPage(); PdfCanvas canvas = new PdfCanvas(page); ImageData img = ImageDataFactory.create(sourceFolder + "2-frames.gif"); canvas.addImage(img, 100, 100, 200, false); document.close(); Assert.assertNull(new CompareTool().compareByContent(destinationFolder + "gifImageTest01.pdf", sourceFolder + "cmp_gifImageTest01.pdf", destinationFolder, "diff_")); }
@Test public void gifImageTest02() throws IOException, InterruptedException { PdfDocument document = new PdfDocument(new PdfWriter(destinationFolder + "gifImageTest02.pdf")); PdfPage page = document.addNewPage(); InputStream is = new FileInputStream(sourceFolder + "2-frames.gif"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); int reads = is.read(); while (reads != -1) { baos.write(reads); reads = is.read(); } PdfCanvas canvas = new PdfCanvas(page); ImageData img = ImageDataFactory.createGifFrame(baos.toByteArray(), 1); canvas.addImage(img, 100, 100, 200, false); document.close(); Assert.assertNull(new CompareTool().compareByContent(destinationFolder + "gifImageTest02.pdf", sourceFolder + "cmp_gifImageTest02.pdf", destinationFolder, "diff_")); }
@Test public void gifImageTest03() throws IOException, InterruptedException { PdfDocument document = new PdfDocument(new PdfWriter(destinationFolder + "gifImageTest03.pdf")); PdfPage page = document.addNewPage(); InputStream is = new FileInputStream(sourceFolder + "2-frames.gif"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); int reads = is.read(); while (reads != -1) { baos.write(reads); reads = is.read(); } PdfCanvas canvas = new PdfCanvas(page); ImageData img = ImageDataFactory.createGifFrame(baos.toByteArray(), 2); canvas.addImage(img, 100, 100, 200, false); document.close(); Assert.assertNull(new CompareTool().compareByContent(destinationFolder + "gifImageTest03.pdf", sourceFolder + "cmp_gifImageTest03.pdf", destinationFolder, "diff_")); }
@Test public void gifImageTest05() throws IOException, InterruptedException { PdfDocument document = new PdfDocument(new PdfWriter(destinationFolder + "gifImageTest05.pdf")); PdfPage page = document.addNewPage(); InputStream is = new FileInputStream(sourceFolder + "animated_fox_dog.gif"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); int reads = is.read(); while (reads != -1) { baos.write(reads); reads = is.read(); } PdfCanvas canvas = new PdfCanvas(page); List<ImageData> frames = ImageDataFactory.createGifFrames(baos.toByteArray(), new int[]{1, 2, 5}); float y = 600; for (ImageData img : frames) { canvas.addImage(img, 100, y, 200, false); y -= 200; } document.close(); Assert.assertNull(new CompareTool().compareByContent(destinationFolder + "gifImageTest05.pdf", sourceFolder + "cmp_gifImageTest05.pdf", destinationFolder, "diff_")); }
@Test public void awtImagesTest01() throws IOException, InterruptedException { String filename = "awtImagesTest01.pdf"; PdfDocument document = new PdfDocument(new PdfWriter(destinationFolder + filename)); PdfPage page = document.addNewPage(); PdfCanvas canvas = new PdfCanvas(page); int x = 36; int y = 700; int width = 100; for (String image : RESOURCES) { java.awt.Image awtImage = Toolkit.getDefaultToolkit().createImage(sourceFolder + image); canvas.addImage(ImageDataFactory.create(awtImage, null), x, y, width, false); y -= 150; } document.close(); Assert.assertNull(new CompareTool().compareByContent(destinationFolder + filename, sourceFolder + "cmp_" + filename, destinationFolder, "diff_")); }