Package com.lowagie.text

Examples of com.lowagie.text.LwgDocument


  public static void main(String[] args) {

    System.out.println("Bookmarks");

    // 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)));
            document.add(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.", new LwgFont(LwgFont.HELVETICA, 12)));
    } catch (Exception de) {
      de.printStackTrace();
    }

    // step 5: we close the document
    document.close();
  }
View Full Code Here


     */
    public static void main(String[] args) {
        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());
            group.add(l3.getRef());
            order.add(group);
            PdfDictionary d = new PdfDictionary();
            d.put(PdfName.ORDER, order);
            p.put(PdfName.D, d);
            // step 5
            document.close();
        }
        catch(Exception de) {
            de.printStackTrace();
        }
    }
View Full Code Here

     */
    public static void main(String[] args) {
        LwgDocument.compress = false;
        System.out.println("Transformating an Image");       
        // step 1: creation of a document-object
        LwgDocument document = new LwgDocument(LwgPageSize.A4);
       
        try {
            // step 2: creation of the writer
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("transformimage.pdf"));
           
            // step 3: we open the document
            document.open();
           
            // step 4:
            PdfContentByte cb = writer.getDirectContent();
            LwgImage img = LwgImage.getInstance("hitchcock.png");
            cb.addImage(img, 271, -50, -30, 550, 100, 100);
            cb.sanityCheck();
  
        }
        catch(DocumentException de) {
            System.err.println(de.getMessage());
        }
        catch(IOException ioe) {
            System.err.println(ioe.getMessage());
        }
       
        // step 5: we close the document
        document.close();
    }
View Full Code Here

    public static void main(String[] args) {
       
        System.out.println("Pantone example : Spot Color");
       
        // step 1: creation of a document-object
        LwgDocument document = new LwgDocument();
        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("spotcolor.pdf"));
            BaseFont bf = BaseFont.createFont("Helvetica", "winansi", BaseFont.NOT_EMBEDDED);
           
            // 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();
        }
       
        // step 5: we close the document
        document.close();
    }
View Full Code Here

     * @param args no arguments needed
     */
    public static void main(String args[]) {
        try {
          // step 1: creating the document
            LwgDocument doc = new LwgDocument(LwgPageSize.A4, 50, 50, 100, 72);
            // step 2: creating the writer
            PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream("pageNumbersWatermark.pdf"));
            // step 3: initialisations + opening the document
            writer.setPageEvent(new PageNumbersWatermark());
            doc.open();
            // step 4: adding content
            String text = "some padding text ";
            for (int k = 0; k < 10; ++k)
                text += text;
            Paragraph p = new Paragraph(text);
            p.setAlignment(LwgElement.ALIGN_JUSTIFIED);
            doc.add(p);
            // step 5: closing the document
            doc.close();
        }
        catch ( Exception e ) {
            e.printStackTrace();
        }
    }
View Full Code Here

     */
    public static void main(String[] args) {
       
        System.out.println("PDF version");       
        // step 1: creation of a document-object
        LwgDocument document = new LwgDocument();
       
        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"));
        }
        catch(DocumentException de) {
            System.err.println(de.getMessage());
        }
        catch(IOException ioe) {
            System.err.println(ioe.getMessage());
        }
       
        // step 5: we close the document
        document.close();
    }
View Full Code Here

    public static void main(String[] args) {
       
        System.out.println("Measurements");       
        // step 1: creation of a document-object
        LwgRectangle pageSize = new LwgRectangle(288, 720);
        LwgDocument document = new LwgDocument(pageSize, 36, 18, 72, 72);
       
        try {
           
            // step 2:
            // we create a writer that listens to the document
            // and directs a PDF-stream to a file
           
            PdfWriter.getInstance(document, new GfrFileOutputStream("com.lowagie.examples.general.faq.Measurements.pdf"));
           
            // step 3: we open the document
            document.open();
           
            // step 4:
            document.add(new Paragraph("The size of this page is 288x720 points."));
            document.add(new Paragraph("288pt / 72 points per inch = 4 inch"));
            document.add(new Paragraph("720pt / 72 points per inch = 10 inch"));
            document.add(new Paragraph("The size of this page is 4x10 inch."));
            document.add(new Paragraph("4 inch x 2.54 = 10.16 cm"));
            document.add(new Paragraph("10 inch x 2.54 = 25.4 cm"));
            document.add(new Paragraph("The size of this page is 10.16x25.4 cm."));
            document.add(new Paragraph("The left border is 36pt or 0.5 inch or 1.27 cm"));
            document.add(new Paragraph("The right border is 18pt or 0.25 inch or 0.63 cm."));
            document.add(new Paragraph("The top and bottom border are 72pt or 1 inch or 2.54 cm."));
        }
        catch(DocumentException de) {
            System.err.println(de.getMessage());
        }
        catch(IOException ioe) {
            System.err.println(ioe.getMessage());
        }
       
        // step 5: we close the document
        document.close();
    }
View Full Code Here

     */
    public static void main(String[] args) {
      System.out.println("layer radio group and zoom");
        try {
          // step 1
            LwgDocument document = new LwgDocument(LwgPageSize.A4, 50, 50, 50, 50);
            // step 2
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("layers.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 radio group and zoom", new LwgFont(LwgFont.HELVETICA, 20, LwgFont.BOLD, Color.red));
            ColumnText.showTextAligned(cb, LwgElement.ALIGN_LEFT, explanation, 50, 650, 0);
            PdfLayer title = PdfLayer.createTitle("Layer radio group", writer);
            PdfLayer l1 = new PdfLayer("Layer 1", writer);
            PdfLayer l2 = new PdfLayer("Layer 2", writer);
            PdfLayer l3 = new PdfLayer("Layer 3", writer);
            PdfLayer l4 = new PdfLayer("Layer 4", writer);
            title.addChild(l1);
            title.addChild(l2);
            title.addChild(l3);
            l4.setZoom(2, -1);
            l4.setOnPanel(false);
            l4.setPrint("Print", true);
            l2.setOn(false);
            l3.setOn(false);
            ArrayList radio = new ArrayList();
            radio.add(l1);
            radio.add(l2);
            radio.add(l3);
            writer.addOCGRadioGroup(radio);
            LwgPhrase p1 = new LwgPhrase("Text in layer 1");
            LwgPhrase p2 = new LwgPhrase("Text in layer 2");
            LwgPhrase p3 = new LwgPhrase("Text in layer 3");
            LwgPhrase p4 = new LwgPhrase("Text in layer 4");
            cb.beginLayer(l1);
            ColumnText.showTextAligned(cb, LwgElement.ALIGN_LEFT, p1, 50, 600, 0);
            cb.endLayer();
            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.beginLayer(l4);
            ColumnText.showTextAligned(cb, LwgElement.ALIGN_LEFT, p4, 50, 450, 0);
            cb.endLayer();
            ColumnText.showTextAligned(cb, LwgElement.ALIGN_LEFT, new LwgPhrase("<< Zoom here!", new LwgFont(LwgFont.COURIER, 12, LwgFont.NORMAL, Color.blue)), 150, 450, 0);
            // step 5
            document.close();
        }
        catch(Exception de) {
            de.printStackTrace();
        }
    }
View Full Code Here

     * @param args Unused
     */
    public static void main(String[] args) {
        System.out.println("Demonstrates creating Table Cells with complex borders");
        try {
            LwgDocument document = new LwgDocument();
            RtfWriter2.getInstance(document, new FileOutputStream("ExtendedTableCell.rtf"));

            document.open();
           
            Table table = new Table(3);

            // Create a simple RtfCell with a dotted border.
            RtfCell cellDotted = new RtfCell("Dotted border");
            cellDotted.setBorders(new RtfBorderGroup(LwgRectangle.BOX,
                    RtfBorder.BORDER_DOTTED, 1, new Color(0, 0, 0)));
           
            // Create a simple RtfCell with an embossed border.
            RtfCell cellEmbossed = new RtfCell("Embossed border");
            cellEmbossed.setBorders(new RtfBorderGroup(LwgRectangle.BOX,
                    RtfBorder.BORDER_EMBOSS, 1, new Color(0, 0, 0)));
           
            // Create a simple RtfCell with no border.
            RtfCell cellNoBorder = new RtfCell("No border");
            cellNoBorder.setBorders(new RtfBorderGroup());
            cellNoBorder.setRowspan(2);
           
            // Create a simple RtfCell that only has a border
            // on the bottom side.
            RtfCell bottomBorder = new RtfCell("Bottom border");
            bottomBorder.setBorders(new RtfBorderGroup(LwgRectangle.BOTTOM,
                    RtfBorder.BORDER_SINGLE, 2, new Color(255, 0, 0)));
           
            // Create a simple RtfCell that has different borders
            // on the left and bottom sides.
            RtfCell mixedBorder = new RtfCell("Mixed border");
            RtfBorderGroup mixedBorders = new RtfBorderGroup();
            mixedBorders.addBorder(LwgRectangle.RIGHT,
                    RtfBorder.BORDER_DOUBLE_WAVY, 2, Color.GREEN);
            mixedBorders.addBorder(LwgRectangle.BOTTOM,
                    RtfBorder.BORDER_DOT_DASH, 1, Color.BLUE);
            mixedBorder.setBorders(mixedBorders);
           
            // Add the cells to the table
            table.addCell(cellDotted);
            table.addCell(cellEmbossed);
            table.addCell(cellNoBorder);
            table.addCell(bottomBorder);
            table.addCell(mixedBorder);
           
            document.add(table);

            document.close();
        } catch (FileNotFoundException fnfe) {
            fnfe.printStackTrace();
        } catch (DocumentException de) {
            de.printStackTrace();
        }
View Full Code Here

     * @param args no arguments needed
     */
    public static void main(String[] args) {
        try {
          // step 1
          LwgDocument document = new LwgDocument();
          // step 2
            PdfWriter.getInstance(document, new FileOutputStream("differentfonts.pdf"));
            // step 3
            document.open();
            // step 4
            Paragraph p = new Paragraph();
            p.add(new Chunk("This text is in Times Roman. This is ZapfDingbats: ", new LwgFont(LwgFont.TIMES_ROMAN, 12)));
            p.add(new Chunk("abcdefghijklmnopqrstuvwxyz", new LwgFont(LwgFont.ZAPFDINGBATS, 12)));
            p.add(new Chunk(". This is font Symbol: ", new LwgFont(LwgFont.TIMES_ROMAN, 12)));
            p.add(new Chunk("abcdefghijklmnopqrstuvwxyz", new LwgFont(LwgFont.SYMBOL, 12)));
            document.add(new Paragraph(p));
            // step 5
            document.close();
        }
        catch(Exception de) {
            de.printStackTrace();
        }
    }
View Full Code Here

TOP

Related Classes of com.lowagie.text.LwgDocument

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.