Package com.lowagie.text.pdf

Examples of com.lowagie.text.pdf.PdfTemplate


            mapper.insertDirectory("c:\\windows\\fonts");
            // we create a template and a Graphics2D object that corresponds with it
            int w = 150;
            int h = 150;
            PdfContentByte cb = writer.getDirectContent();
            PdfTemplate tp = cb.createTemplate(w, h);
            Graphics2D g2 = tp.createGraphics(w, h, mapper);
            tp.setWidth(w);
            tp.setHeight(h);
            double ew = w/2;
            double eh = h/2;
            Ellipse2D.Double circle, oval, leaf, stem;
            Area circ, ov, leaf1, leaf2, st1, st2;
            circle = new Ellipse2D.Double();
            oval = new Ellipse2D.Double();
            leaf = new Ellipse2D.Double();
            stem = new Ellipse2D.Double();
            circ = new Area(circle);
            ov = new Area(oval);
            leaf1 = new Area(leaf);
            leaf2 = new Area(leaf);
            st1 = new Area(stem);
            st2 = new Area(stem);
            g2.setColor(Color.green);
           
            // Creates the first leaf by filling the intersection of two Area objects created from an ellipse.
            leaf.setFrame(ew-16, eh-29, 15.0, 15.0);
            leaf1 = new Area(leaf);
            leaf.setFrame(ew-14, eh-47, 30.0, 30.0);
            leaf2 = new Area(leaf);
            leaf1.intersect(leaf2);
            g2.fill(leaf1);
           
            // Creates the second leaf.
            leaf.setFrame(ew+1, eh-29, 15.0, 15.0);
            leaf1 = new Area(leaf);
            leaf2.intersect(leaf1);
            g2.fill(leaf2);
           
            g2.setColor(Color.black);
           
            // Creates the stem by filling the Area resulting from the subtraction of two Area objects created from an ellipse.
            stem.setFrame(ew, eh-42, 40.0, 40.0);
            st1 = new Area(stem);
            stem.setFrame(ew+3, eh-47, 50.0, 50.0);
            st2 = new Area(stem);
            st1.subtract(st2);
            g2.fill(st1);
           
            g2.setColor(Color.yellow);
           
            // Creates the pear itself by filling the Area resulting from the union of two Area objects created by two different ellipses.
            circle.setFrame(ew-25, eh, 50.0, 50.0);
            oval.setFrame(ew-19, eh-20, 40.0, 70.0);
            circ = new Area(circle);
            ov = new Area(oval);
            circ.add(ov);
            g2.fill(circ);
           
            g2.setColor(Color.black);
            java.awt.Font thisFont = new java.awt.Font("Arial", java.awt.Font.PLAIN, 18);
            g2.setFont(thisFont);
            String pear = "Pear";
            FontMetrics metrics = g2.getFontMetrics();
            int width = metrics.stringWidth(pear);
            g2.drawString(pear, (w - width) / 2, 20);
            g2.dispose();
            tp.sanityCheck(); // all the g2 content is written to tp, not cb
            cb.addTemplate(tp, 50, 400);
            cb.sanityCheck();
        }
        catch(DocumentException de) {
            System.err.println(de.getMessage());
View Full Code Here


            // step 4:
            PdfContentByte cb = writer.getDirectContent();
            cb.transform(AffineTransform.getScaleInstance(1.2, 0.75));
           
            // we create a PdfTemplate
            PdfTemplate template = cb.createTemplate(25, 25);
           
            // we add some crosses to visualize the coordinates
            template.moveTo(13, 0);
            template.lineTo(13, 25);
            template.moveTo(0, 13);
            template.lineTo(50, 13);
            template.stroke();
            template.sanityCheck();
           
            // we add the template on different positions
            cb.addTemplate(template, 216 - 13, 720 - 13);
            cb.addTemplate(template, 360 - 13, 360 - 13);
            cb.addTemplate(template, 360 - 13, 504 - 13);
View Full Code Here

            document.open();
           
            // step 4:
            BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
            PdfContentByte cb = writer.getDirectContent();
            PdfTemplate template = cb.createTemplate(500, 200);
            template.setLineWidth(2f);
            template.rectangle(2.5f, 2.5f, 495f, 195f);
            template.stroke();
            template.setLineWidth(12f);
            template.arc(40f - (float) Math.sqrt(12800), 120f + (float) Math.sqrt(12800), 200f - (float) Math.sqrt(12800), -40f + (float) Math.sqrt(12800), 281.25f, 33.75f);
            template.arc(40f, 120f, 200f, -40f, 90f, 45f);
            template.stroke();
            template.setLineCap(1);
            template.setLineWidth(12f);
            template.arc(80f, 40f, 160f, 120f, 90f, 180f);
            template.arc(115f, 75f, 125f, 85f, 0f, 360f);
            template.stroke();
            template.beginText();
            template.setFontAndSize(bf, 180);
            template.setRGBColorFill(0xFF, 0x00, 0x00);
            template.showTextAligned(PdfContentByte.ALIGN_LEFT, "T", 125f, 35f, 0f);
            template.resetRGBColorFill();
            template.showTextAligned(PdfContentByte.ALIGN_LEFT, "ext", 220f, 35f, 0f);
            template.endText();
            template.sanityCheck();
           
            cb.addTemplate(template, 0, 1, -1, 0, 500, 200);
            cb.addTemplate(template, .5f, 0, 0, .5f, 100, 400);
            cb.addTemplate(template, 0.25f, 0, 0, 0.25f, 100, 100);
            cb.sanityCheck();
View Full Code Here

            gs1.setFillOpacity(0.5f);
            cb.setGState(gs1);
            pictureCircles(200 + 2 * gap, 500, cb);
            cb.restoreState();

            PdfTemplate tp = cb.createTemplate(200, 200);
            cb.saveState();
            pictureCircles(0, 0, tp);
            PdfTransparencyGroup group = new PdfTransparencyGroup();
            tp.setGroup(group);
            tp.sanityCheck();
            cb.setGState(gs1);
            cb.addTemplate(tp, gap, 500 - 200 - gap);
            cb.restoreState();

            tp = cb.createTemplate(200, 200);
            cb.saveState();
            PdfGState gs2 = new PdfGState();
            gs2.setFillOpacity(0.5f);
            gs2.setBlendMode(PdfGState.BM_SOFTLIGHT);
            tp.setGState(gs2);
            tp.sanityCheck();
            pictureCircles(0, 0, tp);
            tp.setGroup(group);
            cb.addTemplate(tp, 200 + 2 * gap, 500 - 200 - gap);
            cb.restoreState();

            cb.resetRGBColorFill();
            ColumnText ct = new ColumnText(cb);
View Full Code Here

            // step 3: we open the document
            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);
View Full Code Here

            String text = "Some text to show";
            document.add(new Paragraph(text, new Font(Font.HELVETICA, 24, Font.NORMAL, new SpotColor(spc_cmyk, 0.25f))));
            document.add(new Paragraph(text, new Font(Font.HELVETICA, 24, Font.NORMAL, new SpotColor(spc_cmyk, 0.5f))));
           
            // example with template
            PdfTemplate t = cb.createTemplate(500f, 500f);
            // Stroke a rectangle with CMYK alternate
            t.setColorStroke(new SpotColor(spc_cmyk, .5f));
            t.setLineWidth(10f);
            // draw a rectangle
            t.rectangle(100, 10, 100, 100);
            // add the diagonal
            t.moveTo(100, 10);
            t.lineTo(200, 100);
            // stroke the lines
            t.stroke();
           
            // Fill a rectangle with CMYK alternate
            t.setColorFill(spc_g, 0.5f);
            t.rectangle(100, 125, 100, 100);
            t.fill();
            t.beginText();
            t.setFontAndSize(bf, 20f);
            t.setTextMatrix(1f, 0f, 0f, 1f, 10f, 10f);
            t.showText("Template text upside down");
            t.endText();
            t.rectangle(0, 0, 499, 499);
            t.stroke();
            t.sanityCheck();
            cb.addTemplate(t, -1.0f, 0.00f, 0.00f, -1.0f, 550f, 550f);
           
            cb.sanityCheck();
        }
        catch(Exception de) {
View Full Code Here

            pictureBackdrop(gap, 500, cb);
            pictureBackdrop(200 + 2 * gap, 500, cb);
            pictureBackdrop(gap, 500 - 200 - gap, cb);
            pictureBackdrop(200 + 2 * gap, 500 - 200 - gap, cb);

            PdfTemplate tp;
            PdfTransparencyGroup group;
           
            tp = cb.createTemplate(200, 200);
            pictureCircles(0, 0, tp);
            group = new PdfTransparencyGroup();
            group.setIsolated(true);
            group.setKnockout(true);
            tp.setGroup(group);
            tp.sanityCheck();
            cb.addTemplate(tp, gap, 500);

           
            tp = cb.createTemplate(200, 200);
            pictureCircles(0, 0, tp);
            group = new PdfTransparencyGroup();
            group.setIsolated(true);
            group.setKnockout(false);
            tp.setGroup(group);
            tp.sanityCheck();
            cb.addTemplate(tp, 200 + 2 * gap, 500);

           
            tp = cb.createTemplate(200, 200);
            pictureCircles(0, 0, tp);
            group = new PdfTransparencyGroup();
            group.setIsolated(false);
            group.setKnockout(true);
            tp.setGroup(group);
            tp.sanityCheck();
            cb.addTemplate(tp, gap, 500 - 200 - gap);

           
            tp = cb.createTemplate(200, 200);
            pictureCircles(0, 0, tp);
            group = new PdfTransparencyGroup();
            group.setIsolated(false);
            group.setKnockout(false);
            tp.setGroup(group);
            tp.sanityCheck();
            cb.addTemplate(tp, 200 + 2 * gap, 500 - 200 - gap);

            cb.sanityCheck();
        }
        catch (Exception de) {
View Full Code Here

            // step3
            document.open();
            // step4
           
            // make a PdfTemplate with the vertical text
            PdfTemplate template = writer.getDirectContent().createTemplate(20, 20);
            BaseFont bf = BaseFont.createFont("Helvetica", "winansi", false);
            String text = "Vertical";
            float size = 16;
            float width = bf.getWidthPoint(text, size);
            template.beginText();
            template.setRGBColorFillF(1, 1, 1);
            template.setFontAndSize(bf, size);
            template.setTextMatrix(0, 2);
            template.showText(text);
            template.endText();
            template.setWidth(width);
            template.setHeight(size + 2);
            // make an Image object from the template
            Image img = Image.getInstance(template);
            img.setRotationDegrees(90);
            PdfPTable table = new PdfPTable(3);
            table.setWidthPercentage(100);
View Full Code Here

        try {
            Image pdfImage = Image.getInstance(image, null);
            pdfImage.setAbsolutePosition(0, 0);
            pdfImage.scaleToFit(width, height);
            PdfTemplate template = this.contentByte.createTemplate(image.getWidth(), image.getHeight());
            template.addImage(pdfImage);
            final float leftMargin = this.document.leftMargin();
            this.contentByte.addTemplate(template, leftMargin + x, y);
        } catch (BadElementException e) {
            throw new GeracaoBoletoException(e);
        } catch (DocumentException e) {
View Full Code Here

        try {
            Image pdfImage = Image.getInstance(image, null);
            pdfImage.setAbsolutePosition(0, 0);
            pdfImage.scaleToFit(width, height);
            PdfTemplate template = contentByte.createTemplate(image.getWidth(), image.getHeight());
            template.addImage(pdfImage);
            final float leftMargin = document.leftMargin();
            contentByte.addTemplate(template, leftMargin + x, y);
        } catch (BadElementException e) {
            throw new GeracaoBoletoException(e);
        } catch (DocumentException e) {
View Full Code Here

TOP

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

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.