Package com.lowagie.text.pdf

Examples of com.lowagie.text.pdf.PdfPatternPainter


      {
        final TexturePaint tp = (TexturePaint)paint;
        final BufferedImage img = tp.getImage();
        final Rectangle2D rect = tp.getAnchorRect();
        final com.lowagie.text.Image image = com.lowagie.text.Image.getInstance(img, null);
        final PdfPatternPainter pattern = cb.createPattern(image.getWidth(), image.getHeight());
        final AffineTransform inverse = this.normalizeMatrix();
        inverse.translate(rect.getX(), rect.getY());
        inverse.scale(rect.getWidth() / image.getWidth(), -rect.getHeight() / image.getHeight());
        final double[] mx = new double[6];
        inverse.getMatrix(mx);
        pattern.setPatternMatrix((float)mx[0], (float)mx[1], (float)mx[2], (float)mx[3], (float)mx[4], (float)mx[5]) ;
        image.setAbsolutePosition(0,0);
        pattern.addImage(image);
        if (fill)
            cb.setPatternFill(pattern);
        else
            cb.setPatternStroke(pattern);

      }
      catch (Exception ex)
      {
        if (fill)
        {
          cb.setColorFill(Color.gray);
        }
        else
        {
          cb.setColorStroke(Color.gray);
        }
      }
    }
    else
    {
      try
      {
        int type = BufferedImage.TYPE_4BYTE_ABGR;
        if (paint.getTransparency() == Transparency.OPAQUE)
        {
          type = BufferedImage.TYPE_3BYTE_BGR;
        }
        final BufferedImage img = new BufferedImage((int) width, (int) height, type);
        final Graphics2D g = (Graphics2D) img.getGraphics();
        g.transform(transform);
        final AffineTransform inv = transform.createInverse();
        Shape fillRect = new Rectangle2D.Double(0, 0, img.getWidth(), img.getHeight());
        fillRect = inv.createTransformedShape(fillRect);
        g.setPaint(paint);
        g.fill(fillRect);
        if (invert)
        {
          final AffineTransform tx = new AffineTransform();
          tx.scale(1, -1);
          tx.translate(-xoffset, -yoffset);
          g.drawImage(img, tx, null);
        }
        g.dispose();
        // g = null;
        final com.lowagie.text.Image image = com.lowagie.text.Image.getInstance(img, null);
        final PdfPatternPainter pattern = cb.createPattern(width, height);
        image.setAbsolutePosition(0, 0);
        pattern.addImage(image);
        if (fill)
        {
          cb.setPatternFill(pattern);
        }
        else
View Full Code Here


      {
        final TexturePaint tp = (TexturePaint)paint;
        final BufferedImage img = tp.getImage();
        final Rectangle2D rect = tp.getAnchorRect();
        final com.lowagie.text.Image image = com.lowagie.text.Image.getInstance(img, null);
        final PdfPatternPainter pattern = cb.createPattern(image.getWidth(), image.getHeight());
        final AffineTransform inverse = this.normalizeMatrix();
        inverse.translate(rect.getX(), rect.getY());
        inverse.scale(rect.getWidth() / image.getWidth(), -rect.getHeight() / image.getHeight());
        final double[] mx = new double[6];
        inverse.getMatrix(mx);
        pattern.setPatternMatrix((float)mx[0], (float)mx[1], (float)mx[2], (float)mx[3], (float)mx[4], (float)mx[5]) ;
        image.setAbsolutePosition(0,0);
        pattern.addImage(image);
        if (fill)
            cb.setPatternFill(pattern);
        else
            cb.setPatternStroke(pattern);

      }
      catch (Exception ex)
      {
        if (fill)
        {
          cb.setColorFill(Color.gray);
        }
        else
        {
          cb.setColorStroke(Color.gray);
        }
      }
    }
    else
    {
      try
      {
        int type = BufferedImage.TYPE_4BYTE_ABGR;
        if (paint.getTransparency() == Transparency.OPAQUE)
        {
          type = BufferedImage.TYPE_3BYTE_BGR;
        }
        final BufferedImage img = new BufferedImage((int) width, (int) height, type);
        final Graphics2D g = (Graphics2D) img.getGraphics();
        g.transform(transform);
        final AffineTransform inv = transform.createInverse();
        Shape fillRect = new Rectangle2D.Double(0, 0, img.getWidth(), img.getHeight());
        fillRect = inv.createTransformedShape(fillRect);
        g.setPaint(paint);
        g.fill(fillRect);
        if (invert)
        {
          final AffineTransform tx = new AffineTransform();
          tx.scale(1, -1);
          tx.translate(-xoffset, -yoffset);
          g.drawImage(img, tx, null);
        }
        g.dispose();
        // g = null;
        final com.lowagie.text.Image image = com.lowagie.text.Image.getInstance(img, null);
        final PdfPatternPainter pattern = cb.createPattern(width, height);
        image.setAbsolutePosition(0, 0);
        pattern.addImage(image);
        if (fill)
        {
          cb.setPatternFill(pattern);
        }
        else
View Full Code Here

            // step 5: we create some PdfPatternPainter instances for drawing path, text, or placing image
           
            // LwgImage instance to be placed in PdfPatternPainter canvas. Any nice one?
            LwgImage img = LwgImage.getInstance("pngnow.png");

            PdfPatternPainter p = cb.createPattern(60f, 60f, 60f, 60f);
            PdfPatternPainter p1 = cb.createPattern(60f, 60f, 60f, 60f);
            PdfPatternPainter p2 = cb.createPattern(img.getScaledWidth(), img.getScaledHeight(), img.getScaledWidth(), img.getScaledHeight());
           
           
            // step 6: put your drawing instruction in the painter canvas
           
            // A star pattern taken from Adobe PDF Reference Book p.207
            String star = "0.3 g\n15.000 27.000 m\n"
            + "7.947 5.292 l\n26.413 18.708 l\n"
            + "3.587 18.708 l\n22.053 5.292 l\nf\n"
            + "45.000 57.000 m\n37.947 35.292 l\n"
            + "56.413 48.708 l\n33.587 48.708 l\n"
            + "52.053 35.292 l\nf\n"
            + "0.7 g\n15.000 57.000 m\n"
            + "7.947 35.292 l\n26.413 48.708 l\n"
            + "3.587 48.708 l\n22.053 35.292 l\nf\n"
            + "45.000 27.000 m\n37.947 5.292 l\n"
            + "56.413 18.708 l\n33.587 18.708 l\n"
            + "52.053 5.292 l\nf";
           
            p.setLiteral(star);
           
            // A Pattern with some text drawing
            p1.setGrayFill(0.3f);
            p1.setFontAndSize(bf, 12);
            p1.beginText();
            p1.setTextMatrix(1f, 0f, 0f, 1f, 0f, 0f);
            p1.showText("A B C D");
            p1.endText();
            p1.moveTo(0f, 0f);
            p1.lineTo(60f, 60f);
            p1.stroke();
            p1.sanityCheck();
           
            // A pattern with an image and position
            p2.addImage(img, img.getScaledWidth(), 0f, 0f, img.getScaledHeight(), 0f, 0f);
            p2.setPatternMatrix(1f, 0f, 0f, 1f, 60f, 60f);
            p2.sanityCheck();
           
            // See if we can apply the pattern color to chunk, phrase or paragraph
            PatternColor pat = new PatternColor(p);
            PatternColor pat1 = new PatternColor(p1);
            PatternColor pat2 = new PatternColor(p2);
View Full Code Here

            document.open();
           
            // step 4: we add some content
            PdfContentByte cb = writer.getDirectContent();
            PdfTemplate tp = cb.createTemplate(400, 300);
            PdfPatternPainter pat = cb.createPattern(15, 15, null);
            pat.rectangle(5, 5, 5, 5);
            pat.fill();
            pat.sanityCheck();
           
            PdfSpotColor spc_cmyk = new PdfSpotColor("PANTONE 280 CV", new CMYKColor(0.9f, .2f, .3f, .1f));
            SpotColor spot = new SpotColor(spc_cmyk, 0.25f);
            tp.setPatternFill(pat, spot, .9f);
            tp.rectangle(0, 0, 400, 300);
            tp.fill();
            tp.sanityCheck();
           
            cb.addTemplate(tp, 50, 50);
            PdfPatternPainter pat2 = cb.createPattern(10, 10, null);
            pat2.setLineWidth(2);
            pat2.moveTo(-5, 0);
            pat2.lineTo(10, 15);
            pat2.stroke();
            pat2.moveTo(0, -5);
            pat2.lineTo(15, 10);
            pat2.stroke();
            cb.setLineWidth(1);
            cb.setColorStroke(Color.black);
            cb.setPatternFill(pat2, Color.red);
            cb.rectangle(100, 400, 30, 210);
            cb.fillStroke();
View Full Code Here

            document.open();
           
            // step 4: we add some content
            PdfContentByte cb = writer.getDirectContent();
            PdfTemplate tp = cb.createTemplate(400, 300);
            PdfPatternPainter pat = cb.createPattern(15, 15, null);
            pat.rectangle(5, 5, 5, 5);
            pat.fill();
            pat.sanityCheck();
           
            PdfSpotColor spc_cmyk = new PdfSpotColor("PANTONE 280 CV", new CMYKColor(0.9f, .2f, .3f, .1f));
            SpotColor spot = new SpotColor(spc_cmyk, 0.25f);
            tp.setPatternFill(pat, spot, .9f);
            tp.rectangle(0, 0, 400, 300);
            tp.fill();
            tp.sanityCheck();
           
            cb.addTemplate(tp, 50, 50);
            PdfPatternPainter pat2 = cb.createPattern(10, 10, null);
            pat2.setLineWidth(2);
            pat2.moveTo(-5, 0);
            pat2.lineTo(10, 15);
            pat2.stroke();
            pat2.moveTo(0, -5);
            pat2.lineTo(15, 10);
            pat2.stroke();
            cb.setLineWidth(1);
            cb.setColorStroke(Color.black);
            cb.setPatternFill(pat2, Color.red);
            cb.rectangle(100, 400, 30, 210);
            cb.fillStroke();
View Full Code Here

            // step 5: we create some PdfPatternPainter instances for drawing path, text, or placing image
           
            // Image instance to be placed in PdfPatternPainter canvas. Any nice one?
            Image img = Image.getInstance("pngnow.png");

            PdfPatternPainter p = cb.createPattern(60f, 60f, 60f, 60f);
            PdfPatternPainter p1 = cb.createPattern(60f, 60f, 60f, 60f);
            PdfPatternPainter p2 = cb.createPattern(img.getScaledWidth(), img.getScaledHeight(), img.getScaledWidth(), img.getScaledHeight());
           
           
            // step 6: put your drawing instruction in the painter canvas
           
            // A star pattern taken from Adobe PDF Reference Book p.207
            String star = "0.3 g\n15.000 27.000 m\n"
            + "7.947 5.292 l\n26.413 18.708 l\n"
            + "3.587 18.708 l\n22.053 5.292 l\nf\n"
            + "45.000 57.000 m\n37.947 35.292 l\n"
            + "56.413 48.708 l\n33.587 48.708 l\n"
            + "52.053 35.292 l\nf\n"
            + "0.7 g\n15.000 57.000 m\n"
            + "7.947 35.292 l\n26.413 48.708 l\n"
            + "3.587 48.708 l\n22.053 35.292 l\nf\n"
            + "45.000 27.000 m\n37.947 5.292 l\n"
            + "56.413 18.708 l\n33.587 18.708 l\n"
            + "52.053 5.292 l\nf";
           
            p.setLiteral(star);
           
            // A Pattern with some text drawing
            p1.setGrayFill(0.3f);
            p1.setFontAndSize(bf, 12);
            p1.beginText();
            p1.setTextMatrix(1f, 0f, 0f, 1f, 0f, 0f);
            p1.showText("A B C D");
            p1.endText();
            p1.moveTo(0f, 0f);
            p1.lineTo(60f, 60f);
            p1.stroke();
            p1.sanityCheck();
           
            // A pattern with an image and position
            p2.addImage(img, img.getScaledWidth(), 0f, 0f, img.getScaledHeight(), 0f, 0f);
            p2.setPatternMatrix(1f, 0f, 0f, 1f, 60f, 60f);
            p2.sanityCheck();
           
            // See if we can apply the pattern color to chunk, phrase or paragraph
            PatternColor pat = new PatternColor(p);
            PatternColor pat1 = new PatternColor(p1);
            PatternColor pat2 = new PatternColor(p2);
View Full Code Here

TOP

Related Classes of com.lowagie.text.pdf.PdfPatternPainter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.