Package com.lowagie.text.pdf

Examples of com.lowagie.text.pdf.PdfWriter


        System.out.println("nested layers");
        try {
          // step 1
            LwgDocument document = new LwgDocument(LwgPageSize.A4, 50, 50, 50, 50);
            // step 2
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("nestedlayers.pdf"));
            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());
            PdfArray group = new PdfArray();
            group.add(l2.getRef());
View Full Code Here


        try {
           
            // step 2:
            // we create a writer that listens to the document
            // and directs a PDF-stream to a file
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("pdfversion.pdf"));
            writer.setPdfVersion(PdfWriter.VERSION_1_2);
            // step 3: we open the document
            document.open();
           
            // step 4:
            document.add(new Paragraph("This is a PDF-1.2 document"));
View Full Code Here

    // step 1: creation of a document-object
    LwgDocument document = new LwgDocument(LwgPageSize.A6);
    try {

      // step 2:
      PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("Bookmarks.pdf"));
      // step 3:
            writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
      document.open();
            // step 4: we grab the ContentByte and do some stuff with it
            writer.setPageEvent(new Bookmarks());
           
            document.add(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.", new LwgFont(LwgFont.HELVETICA, 12)));
            document.add(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.]", new LwgFont(LwgFont.HELVETICA, 12)));
            document.add(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.", new LwgFont(LwgFont.HELVETICA, 12)));
            document.add(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.", new LwgFont(LwgFont.HELVETICA, 12)));
View Full Code Here

        LwgDocument document = new LwgDocument();
       
        try {
           
            // step 2: creation of the writer
            PdfWriter writer = PdfWriter.getInstance(document, new GfrFileOutputStream("com.lowagie.examples.objects.columns.ColumnIrregular.pdf"));
           
            // step 3: we open the document
            document.open();
           
            // step 4:
            // we grab the contentbyte and do some stuff with it
            PdfContentByte cb = writer.getDirectContent();
           
            PdfTemplate t = cb.createTemplate(600, 800);
            LwgImage caesar = LwgImage.getInstance("caesar_coin.jpg");
            cb.addImage(caesar, 100, 0, 0, 100, 260, 595);
            t.setGrayFill(0.75f);
View Full Code Here

    // step 1: creation of a document-object
    LwgDocument document = new LwgDocument();
    LwgDocument remote = new LwgDocument();
    try {
            // step 2:
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("OutlineActions.pdf"));
            PdfWriter.getInstance(remote, new FileOutputStream("remote.pdf"));
            // step 3:
            writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
            document.open();
            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");
View Full Code Here

       
        // step 1: creation of a document-object
        LwgDocument document = new LwgDocument(LwgPageSize.A4, 50, 50, 50, 50);
        try {
            // step 2: we create a writer that listens to the document
            PdfWriter writer=PdfWriter.getInstance(document, new FileOutputStream("ChapterSection.pdf"));
            // step 3: we open the document
            writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
            document.open();
            // step 4: we add content to the document
            // we define some fonts
            LwgFont chapterFont = FontFactory.getFont(FontFactory.HELVETICA, 24, LwgFont.NORMAL, new Color(255, 0, 0));
            LwgFont sectionFont = FontFactory.getFont(FontFactory.HELVETICA, 20, LwgFont.NORMAL, new Color(0, 0, 255));
View Full Code Here

        LwgDocument document = new LwgDocument();
       
        try {
           
            // step 2:
            PdfWriter writerA = PdfWriter.getInstance(document, new FileOutputStream("DocumentA.pdf"));
            PdfWriter writerB = PdfWriter.getInstance(document, new FileOutputStream("DocumentB.pdf"));
           
            // step 3: we open the document
            document.open();
           
            // step 4:
           
            // we create some content
           
            // a paragraph with a link to an external url
            Paragraph p1 = new Paragraph("You can turn a Chunk into an ", FontFactory.getFont(FontFactory.HELVETICA, 12));
            p1.add(new Chunk("anchor", FontFactory.getFont(FontFactory.HELVETICA, 12, LwgFont.UNDERLINE, new Color(0, 0, 255))).setAnchor(new URL("http://www.lowagie.com/iText/")));
            p1.add(", for instance to the iText site.");
           
            // some paragraph
            Paragraph p2 = new Paragraph("blah, blah, blah");
           
            // two paragraphs with a local destination
            Paragraph p3a = new Paragraph("This paragraph contains a ");
            p3a.add(new Chunk("local destination in document A", FontFactory.getFont(FontFactory.HELVETICA, 12, LwgFont.NORMAL, new Color(0, 255, 0))).setLocalDestination("test"));
            Paragraph p3b = new Paragraph("This paragraph contains a ");
            p3b.add(new Chunk("local destination in document B", FontFactory.getFont(FontFactory.HELVETICA, 12, LwgFont.NORMAL, new Color(0, 255, 0))).setLocalDestination("test"));
           
            // two paragraphs with a remote goto
            Paragraph p4a = new Paragraph(new Chunk("Click this paragraph to go to a certain destination on document B").setRemoteGoto("DocumentB.pdf", "test"));
            Paragraph p4b = new Paragraph(new Chunk("Click this paragraph to go to a certain destination on document A").setRemoteGoto("DocumentA.pdf", "test"));
           
            // a special remote goto
            Paragraph p5a = new Paragraph("you can also jump to a ");
            p5a.add(new Chunk("specific page on another document", FontFactory.getFont(FontFactory.HELVETICA, 12, LwgFont.ITALIC)).setRemoteGoto("DocumentB.pdf", 3));
           
            // we add all the content
            document.add(p1);
            document.add(p2);
            document.add(p2);
            document.add(p2);
            document.add(p2);
            document.add(p2);
            document.add(p2);
            document.add(p2);
            // only for DocumentB.pdf:
            writerA.pause();
            document.add(p4b);
            writerA.resume();
            // only for DocumentA.pdf:
            writerB.pause();
            document.add(p4a);
            document.add(p5a);
            writerB.resume();
            // for both documents:
            document.add(p2);
            document.add(p2);
            document.add(p2);
            document.add(p2);
            // only for DocumentB.pdf:
            writerA.pause();
            document.add(p3b);
            document.add(p2);
            document.add(p2);
            document.newPage();
            document.add(p2);
            document.add(p2);
            document.newPage();
            writerA.resume();
            // only for documentA.pdf
            writerB.pause();
            document.add(p3a);
            writerB.resume();
            // for both documents
            document.add(p2);
            document.add(p2);
        }
        catch(DocumentException de) {
View Full Code Here

    // step 1: creation of a document-object
    LwgDocument document = new LwgDocument();
    try {

      // step 2:
      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
View Full Code Here

    public static void main(String[] args) {
        try {
          // step 1
            LwgDocument document = new LwgDocument();
            OutputStream out = new FileOutputStream("multicolumnirregular.pdf");
            PdfWriter writer = PdfWriter.getInstance(document, out);
            document.open();

            // calculate diamond shaped hole
            float diamondHeight = 400;
            float diamondWidth = 400;
            float gutter = 10;
            float bodyHeight = document.top() - document.bottom();
            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()};
View Full Code Here

    LwgDocument document1 = new LwgDocument(LwgPageSize.A4, 10, 10, 10, 10);
    LwgDocument document2 = new LwgDocument(LwgPageSize.A4, 10, 10, 10, 10);
    try {

      // step 2:
      PdfWriter writer1 = PdfWriter.getInstance(document1,
          new FileOutputStream("SimpleAnnotations1.pdf"));
      PdfWriter writer2 = PdfWriter.getInstance(document2,
          new FileOutputStream("SimpleAnnotations2.pdf"));
      // step 3:
            writer2.setPdfVersion(PdfWriter.VERSION_1_5);
      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");
View Full Code Here

TOP

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

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.