Package com.lowagie.text.pdf

Examples of com.lowagie.text.pdf.PdfContentByte


            writer.setPdfVersion(PdfWriter.VERSION_1_5);
            writer.setViewerPreferences(PdfWriter.PageModeUseOC);
            // step 3
            document.open();
            // step 4
            PdfContentByte cb = writer.getDirectContent();
            LwgPhrase explanation = new LwgPhrase("Layer nesting", new LwgFont(LwgFont.HELVETICA, 20, LwgFont.BOLD, Color.red));
            ColumnText.showTextAligned(cb, LwgElement.ALIGN_LEFT, explanation, 50, 650, 0);
            PdfLayer l1 = new PdfLayer("Layer 1", writer);
            PdfLayer l23 = new PdfLayer("Top Layer 2 3", writer);
            PdfLayer l2 = new PdfLayer("Layer 2", writer);
            PdfLayer l3 = new PdfLayer("Layer 3", writer);
            LwgPhrase p1 = new LwgPhrase("Text in layer 1");
            LwgPhrase p2 = new LwgPhrase("Text in layer 2");
            LwgPhrase p3 = new LwgPhrase("Text in layer 3");
            cb.beginLayer(l1);
            ColumnText.showTextAligned(cb, LwgElement.ALIGN_LEFT, p1, 50, 600, 0);
            cb.endLayer();
            cb.beginLayer(l23);
            cb.beginLayer(l2);
            ColumnText.showTextAligned(cb, LwgElement.ALIGN_LEFT, p2, 50, 550, 0);
            cb.endLayer();
            cb.beginLayer(l3);
            ColumnText.showTextAligned(cb, LwgElement.ALIGN_LEFT, p3, 50, 500, 0);
            cb.endLayer();
            cb.endLayer();
            cb.sanityCheck();
           
            PdfOCProperties p = writer.getOCProperties();
            PdfArray order = new PdfArray();
            order.add(l1.getRef());
            order.add(l23.getRef());
View Full Code Here


           
            // step 3: we open the document
            document.open();
           
            // step 4: we grab the ContentByte and do some stuff with it
            PdfContentByte cb = writer.getDirectContent();
           
            // step 5: we instantiate PdfSpotColor
           
            // Note: I made up these names unless someone give me a PANTONE swatch as gift (phillip@formstar.com)
            PdfSpotColor spc_cmyk = new PdfSpotColor("PANTONE 280 CV", new CMYKColor(0.9f, .2f, .3f, .1f));
            PdfSpotColor spc_rgb = new PdfSpotColor("PANTONE 147", new Color(114, 94, 38));
            PdfSpotColor spc_g = new PdfSpotColor("PANTONE 100 CV", new GrayColor(0.9f));
           
            // Stroke a rectangle with CMYK alternate
            cb.setColorStroke(spc_cmyk, .5f);
            cb.setLineWidth(10f);
            // draw a rectangle
            cb.rectangle(100, 700, 100, 100);
            // add the diagonal
            cb.moveTo(100, 700);
            cb.lineTo(200, 800);
            // stroke the lines
            cb.stroke();
           
            // Fill a rectangle with CMYK alternate
            cb.setColorFill(spc_cmyk, 0.25f);
            cb.rectangle(250, 700, 100, 100);
            cb.fill();
           
            // Stroke a circle with RGB alternate
            cb.setColorStroke(spc_rgb, 0.9f);
            cb.setLineWidth(5f);
            cb.circle(150f, 500f, 100f);
            cb.stroke();
           
            // Fill the circle with RGB alternate
            cb.setColorFill(spc_rgb, 0.9f);
            cb.circle(150f, 500f, 50f);
            cb.fill();
           
            // example with colorfill
            cb.setColorFill(spc_g, 0.5f);
            cb.moveTo(100f, 200f);
            cb.lineTo(200f, 250f);
            cb.lineTo(400f, 150f);
            cb.fill();
            // cb.sanityCheck is called during newPage().
            document.newPage();
            String text = "Some text to show";
            document.add(new Paragraph(text, new LwgFont(LwgFont.HELVETICA, 24, LwgFont.NORMAL, new SpotColor(spc_cmyk, 0.25f))));
            document.add(new Paragraph(text, new LwgFont(LwgFont.HELVETICA, 24, LwgFont.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) {
            de.printStackTrace();
        }
       
View Full Code Here

   
    /**
     * @see com.lowagie.text.pdf.PdfPageEventHelper#onEndPage(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document)
     */
    public void onEndPage(PdfWriter writer, LwgDocument document) {
        PdfContentByte cb = writer.getDirectContent();
        cb.saveState();
        // write the headertable
        table.setTotalWidth(document.right() - document.left());
        table.writeSelectedRows(0, -1, document.left(), document.getPageSize().getHeight() - 50, cb);
        // compose the footer
        String text = "Page " + writer.getPageNumber() + " of ";
        float textSize = helv.getWidthPoint(text, 12);
        float textBase = document.bottom() - 20;
        cb.beginText();
        cb.setFontAndSize(helv, 12);
        // for odd pagenumbers, show the footer at the left
        if ((writer.getPageNumber() & 1) == 1) {
            cb.setTextMatrix(document.left(), textBase);
            cb.showText(text);
            cb.endText();
            cb.addTemplate(tpl, document.left() + textSize, textBase);
        }
        // for even numbers, show the footer at the right
        else {
            float adjust = helv.getWidthPoint("0", 12);
            cb.setTextMatrix(document.right() - textSize - adjust, textBase);
            cb.showText(text);
            cb.endText();
            cb.addTemplate(tpl, document.right() - adjust, textBase);
        }
        cb.saveState();
        // draw a LwgRectangle around the page
        cb.setColorStroke(Color.orange);
        cb.setLineWidth(2);
        cb.rectangle(20, 20, document.getPageSize().getWidth() - 40, document.getPageSize().getHeight() - 40);
        cb.stroke();
        cb.restoreState();
        // starting on page 3, a watermark with an LwgImage that is made transparent
        if (writer.getPageNumber() >= 3) {
            cb.setGState(gstate);
            cb.setColorFill(Color.red);
            cb.beginText();
            cb.setFontAndSize(helv, 48);
            cb.showTextAligned(LwgElement.ALIGN_CENTER, "Watermark Opacity " + writer.getPageNumber(), document.getPageSize().getWidth() / 2, document.getPageSize().getHeight() / 2, 45);
            cb.endText();
            try {
                cb.addImage(headerImage, headerImage.getWidth(), 0, 0, headerImage.getHeight(), 440, 80);
            }
            catch(Exception e) {
                throw new ExceptionConverter(e);
            }
            cb.restoreState();
        }
        cb.sanityCheck();
    }
View Full Code Here

     * @param document
     * @param position
     */
    public void onParagraph(PdfWriter writer, LwgDocument document, float position) {
        n++;
        PdfContentByte cb = writer.getDirectContent();
        PdfDestination destination = new PdfDestination(PdfDestination.FITH, position);
        new PdfOutline(cb.getRootOutline(), destination, "paragraph " + n);
    }
View Full Code Here

            remote.open();
            // step 4:
            // we add some content
            document.add(new Paragraph("Outline action example"));
            // we add the outline
            PdfContentByte cb = writer.getDirectContent();
            PdfOutline root = cb.getRootOutline();
            PdfOutline links = new PdfOutline(root, new PdfAction("http://www.lowagie.com/iText/links.html"), "Useful links");
            links.setColor(new Color(0x00, 0x80, 0x80));
            links.setStyle(LwgFont.BOLD);
            new PdfOutline(links, new PdfAction("http://www.lowagie.com/iText"), "Bruno's iText site");
            new PdfOutline(links, new PdfAction("http://itextpdf.sourceforge.net/"), "Paulo's iText site");
View Full Code Here

      PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("Destinations.pdf"));
      // step 3:      
            writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
      document.open();
            // step 4: we grab the ContentByte and do some stuff with it
            PdfContentByte cb = writer.getDirectContent();
           
            // we create a PdfTemplate
            PdfTemplate template = cb.createTemplate(25, 25);
           
            // we add some crosses to visualize the destinations
            template.moveTo(13, 0);
            template.lineTo(13, 25);
            template.moveTo(0, 13);
            template.lineTo(50, 13);
            template.stroke();
           
            // we add the template on different positions
            cb.addTemplate(template, 287, 787);
            cb.addTemplate(template, 187, 487);
            cb.addTemplate(template, 487, 287);
            cb.addTemplate(template, 87, 87);
           
            // we define the destinations
            PdfDestination d1 = new PdfDestination(PdfDestination.XYZ, 300, 800, 0);
            PdfDestination d2 = new PdfDestination(PdfDestination.FITH, 500);
            PdfDestination d3 = new PdfDestination(PdfDestination.FITR, 200, 300, 400, 500);
            PdfDestination d4 = new PdfDestination(PdfDestination.FITBV, 100);
            PdfDestination d5 = new PdfDestination(PdfDestination.FIT);
           
            // we define the outlines
            PdfOutline out1 = new PdfOutline(cb.getRootOutline(), d1, "root");
            PdfOutline out2 = new PdfOutline(out1, d2, "sub 1");
            new PdfOutline(out1, d3, "sub 2");
            new PdfOutline(out2, d4, "sub 2.1");
            new PdfOutline(out2, d5, "sub 2.2");
    } catch (Exception de) {
View Full Code Here

            float colMaxWidth = (document.right() - document.left() - (gutter * 2)) / 2f;
            float diamondTop = document.top() - ((bodyHeight - diamondHeight) / 2f);
            float diamondInset = colMaxWidth - (diamondWidth / 2f);
            float centerX = (document.right() - document.left()) / 2 + document.left();
            // draw stuff
            PdfContentByte cb = writer.getDirectContentUnder();
           
            MultiColumnText mct = new MultiColumnText(document.top() - document.bottom());

            // setup column 1
            float[] left = {document.left(), document.top(), document.left(), document.bottom()};
            float[] right = {document.left() + colMaxWidth, document.top(),
                             document.left() + colMaxWidth, diamondTop,
                             document.left() + diamondInset, diamondTop - diamondHeight / 2,
                             document.left() + colMaxWidth, diamondTop - diamondHeight,
                             document.left() + colMaxWidth, document.bottom()
                            };
            mct.addColumn(left, right);

            // setup column 2
            left = new float[] { document.right() - colMaxWidth, document.top(),
                                  document.right() - colMaxWidth, diamondTop,
                                  document.right() - diamondInset, diamondTop - diamondHeight / 2,
                                  document.right() - colMaxWidth, diamondTop - diamondHeight,
                                  document.right() - colMaxWidth, document.bottom()
                                 };
            right = new float[] { document.right(), document.top(), document.right(), document.bottom() };
            mct.addColumn(left, right);

            // add text
            for (int i=0; i<8; i++) {
                mct.addElement(new Paragraph("GALLIA est omnis divisa in partes tres, quarum unam incolunt Belgae, aliam Aquitani, tertiam qui ipsorum lingua Celtae, nostra Galli appellantur.  Hi omnes lingua, institutis, legibus inter se differunt. Gallos ab Aquitanis Garumna flumen, a Belgis Matrona et Sequana dividit. Horum omnium fortissimi sunt Belgae, propterea quod a cultu atque humanitate provinciae longissime absunt, minimeque ad eos mercatores saepe commeant atque ea quae ad effeminandos animos pertinent important, proximique sunt Germanis, qui trans Rhenum incolunt, quibuscum continenter bellum gerunt.  Qua de causa Helvetii quoque reliquos Gallos virtute praecedunt, quod fere cotidianis proeliis cum Germanis contendunt, cum aut suis finibus eos prohibent aut ipsi in eorum finibus bellum gerunt.\n", FontFactory.getFont(FontFactory.HELVETICA, 12)));
                mct.addElement(new Paragraph("[Eorum una, pars, quam Gallos obtinere dictum est, initium capit a flumine Rhodano, continetur Garumna flumine, Oceano, finibus Belgarum, attingit etiam ab Sequanis et Helvetiis flumen Rhenum, vergit ad septentriones. Belgae ab extremis Galliae finibus oriuntur, pertinent ad inferiorem partem fluminis Rheni, spectant in septentrionem et orientem solem. Aquitania a Garumna flumine ad Pyrenaeos montes et eam partem Oceani quae est ad Hispaniam pertinet; spectat inter occasum solis et septentriones.]\n", FontFactory.getFont(FontFactory.HELVETICA, 12)));
                mct.addElement(new Paragraph("Apud Helvetios longe nobilissimus fuit et ditissimus Orgetorix.  Is M. Messala, [et P.] M.  Pisone consulibus regni cupiditate inductus coniurationem nobilitatis fecit et civitati persuasit ut de finibus suis cum omnibus copiis exirent:  perfacile esse, cum virtute omnibus praestarent, totius Galliae imperio potiri.  Id hoc facilius iis persuasit, quod undique loci natura Helvetii continentur:  una ex parte flumine Rheno latissimo atque altissimo, qui agrum Helvetium a Germanis dividit; altera ex parte monte Iura altissimo, qui est inter Sequanos et Helvetios; tertia lacu Lemanno et flumine Rhodano, qui provinciam nostram ab Helvetiis dividit.  His rebus fiebat ut et minus late vagarentur et minus facile finitimis bellum inferre possent; qua ex parte homines bellandi cupidi magno dolore adficiebantur.  Pro multitudine autem hominum et pro gloria belli atque fortitudinis angustos se fines habere arbitrabantur, qui in longitudinem milia passuum CCXL, in latitudinem CLXXX patebant.\n", FontFactory.getFont(FontFactory.HELVETICA, 12)));
                mct.addElement(new Paragraph("His rebus adducti et auctoritate Orgetorigis permoti constituerunt ea quae ad proficiscendum pertinerent comparare, iumentorum et carrorum quam maximum numerum coemere, sementes quam maximas facere, ut in itinere copia frumenti suppeteret, cum proximis civitatibus pacem et amicitiam confirmare.  Ad eas res conficiendas biennium sibi satis esse duxerunt; in tertium annum profectionem lege confirmant.  Ad eas res conficiendas Orgetorix deligitur.  Is sibi legationem ad civitates suscipit.  In eo itinere persuadet Castico, Catamantaloedis filio, Sequano, cuius pater regnum in Sequanis multos annos obtinuerat et a senatu populi Romani amicus appellatus erat, ut regnum in civitate sua occuparet, quod pater ante habuerit; itemque Dumnorigi Haeduo, fratri Diviciaci, qui eo tempore principatum in civitate obtinebat ac maxime plebi acceptus erat, ut idem conaretur persuadet eique filiam suam in matrimonium dat.  Perfacile factu esse illis probat conata perficere, propterea quod ipse suae civitatis imperium obtenturus esset:  non esse dubium quin totius Galliae plurimum Helvetii possent; se suis copiis suoque exercitu illis regna conciliaturum confirmat.  Hac oratione adducti inter se fidem et ius iurandum dant et regno occupato per tres potentissimos ac firmissimos populos totius Galliae sese potiri posse sperant.\n", FontFactory.getFont(FontFactory.HELVETICA, 12)));
                mct.addElement(new Paragraph("Ea res est Helvetiis per indicium enuntiata.  Moribus suis Orgetoricem ex vinculis causam dicere coegerunt; damnatum poenam sequi oportebat, ut igni cremaretur.  Die constituta causae dictionis Orgetorix ad iudicium omnem suam familiam, ad hominum milia decem, undique coegit, et omnes clientes obaeratosque suos, quorum magnum numerum habebat, eodem conduxit; per eos ne causam diceret se eripuit.  Cum civitas ob eam rem incitata armis ius suum exequi conaretur multitudinemque hominum ex agris magistratus cogerent, Orgetorix mortuus est; neque abest suspicio, ut Helvetii arbitrantur, quin ipse sibi mortem consciverit.", FontFactory.getFont(FontFactory.HELVETICA, 12)));
            }
           do {
                cb.setLineWidth(5);
                cb.setColorStroke(Color.GRAY);
                cb.moveTo(centerX , document.top());
                cb.lineTo(centerX, document.bottom());
                cb.stroke();
                cb.moveTo(centerX, diamondTop);
                cb.lineTo(centerX - (diamondWidth/2), diamondTop - (diamondHeight / 2));
                cb.lineTo(centerX, diamondTop - diamondHeight);
                cb.lineTo(centerX + (diamondWidth/2), diamondTop - (diamondHeight / 2));
                cb.lineTo(centerX, diamondTop);
                cb.setColorFill(Color.GRAY);
                cb.fill();
              document.add(mct);
              mct.nextColumn();
            } while (mct.isOverflow());
            document.close();
        } catch (DocumentException e) {
View Full Code Here

      document1.open();
      document2.open();
      // step 4:
      document1.add(new Paragraph("Each square on this page represents an annotation."));
      // document1
            PdfContentByte cb1 = writer1.getDirectContent();
            Annotation a1 = new Annotation(
                "authors", "Maybe it's because I wanted to be an author myself that I wrote iText.",
          250f, 700f, 350f, 800f);
            document1.add(a1);
            Annotation a2 = new Annotation(250f, 550f, 350f, 650f,
                new URL("http://www.lowagie.com/iText/"));
            document1.add(a2);
            Annotation a3 = new Annotation(250f, 400f, 350f, 500f,
                "http://www.lowagie.com/iText");
            document1.add(a3);
      LwgImage image = LwgImage.getInstance("iText.gif");
      image.setAnnotation(a3);
      document1.add(image);
            Annotation a4 = new Annotation(
                250f, 250f, 350f, 350f, PdfAction.LASTPAGE);
            document1.add(a4);
            // draw rectangles to show where the annotations were added
            cb1.rectangle(250, 700, 100, 100);
            cb1.rectangle(250, 550, 100, 100);
            cb1.rectangle(250, 400, 100, 100);
            cb1.rectangle(250, 250, 100, 100);
            cb1.stroke();
            // more content
            document1.newPage();
            for (int i = 0; i < 5; i++) {
              document1.add(new Paragraph("blahblahblah"));
            }
            document1.add(new Annotation("blahblah", "Adding an annotation without specifying coordinates"));
            for (int i = 0; i < 3; i++) {
              document1.add(new Paragraph("blahblahblah"))
            }
            document1.newPage();
            document1.add(new Chunk("marked chunk").setLocalDestination("mark"));
           
            // document2
      document2.add(new Paragraph("Each square on this page represents an annotation."));
            PdfContentByte cb2 = writer2.getDirectContent();
            Annotation a5 = new Annotation(100f, 700f, 200f, 800f,
                "cards.mpg", "video/mpeg", true);
            document2.add(a5);
            Annotation a6 = new Annotation(100f, 550f, 200f, 650f,
                "SimpleAnnotations1.pdf", "mark");
            document2.add(a6);
            Annotation a7 = new Annotation(100f, 400f, 200f, 500f,
                "SimpleAnnotations1.pdf", 2);
            document2.add(a7);
            Annotation a8 = new Annotation100f, 250f, 200f, 350f,
                "C://windows/notepad.exe", null, null, null);
            document2.add(a8);
            // draw rectangles to show where the annotations were added
            cb2.rectangle(100, 700, 100, 100);
            cb2.rectangle(100, 550, 100, 100);
            cb2.rectangle(100, 400, 100, 100);
            cb2.rectangle(100, 250, 100, 100);
            cb2.stroke();
    } catch (Exception de) {
      de.printStackTrace();
    }

    // step 5: we close the document
View Full Code Here

    */
   @Override
   public void onParagraph(PdfWriter writer, LwgDocument document, float position)
   {
      n++;
      PdfContentByte cb = writer.getDirectContent();
      PdfDestination destination = new PdfDestination(PdfDestination.FITH, position);
      new PdfOutline(cb.getRootOutline(), destination, "paragraph " + n);
   }
View Full Code Here

      writer.setPdfVersion(PdfWriter.VERSION_1_5);
      // step 3:
      writer.setViewerPreferences(PdfWriter.PageModeUseOC);
      document.open();
      // step 4:
      PdfContentByte cb = writer.getDirectContent();
      LwgPhrase explanation = new LwgPhrase("Layer grouping", new LwgFont(
          LwgFont.HELVETICA, 20, LwgFont.BOLD, Color.red));
      ColumnText.showTextAligned(cb, LwgElement.ALIGN_LEFT, explanation, 50,
          650, 0);
      PdfLayer l1 = new PdfLayer("Layer 1", writer);
      PdfLayer l2 = new PdfLayer("Layer 2", writer);
      PdfLayer l3 = new PdfLayer("Layer 3", writer);
      PdfLayerMembership m1 = new PdfLayerMembership(writer);
      m1.addMember(l2);
      m1.addMember(l3);
      LwgPhrase p1 = new LwgPhrase("Text in layer 1");
      LwgPhrase p2 = new LwgPhrase("Text in layer 2 or layer 3");
      LwgPhrase p3 = new LwgPhrase("Text in layer 3");
      cb.beginLayer(l1);
      ColumnText.showTextAligned(cb, LwgElement.ALIGN_LEFT, p1, 50, 600, 0);
      cb.endLayer();
      cb.beginLayer(m1);
      ColumnText.showTextAligned(cb, LwgElement.ALIGN_LEFT, p2, 50, 550, 0);
      cb.endLayer();
      cb.beginLayer(l3);
      ColumnText.showTextAligned(cb, LwgElement.ALIGN_LEFT, p3, 50, 500, 0);
      cb.endLayer();
      PdfOCProperties p = writer.getOCProperties();
      PdfArray order = new PdfArray();
      order.add(l1.getRef());
      PdfArray group = new PdfArray();
      group.add(new PdfString("A group of two", PdfObject.TEXT_UNICODE));
View Full Code Here

TOP

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

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.