Package com.lowagie.text

Examples of com.lowagie.text.LwgDocument


  public static void main(String[] args) {

    System.out.println("Standard Type 1 fonts: FontFactory");

    // step 1: creation of a document-object
    LwgDocument document = new LwgDocument();
    try {
      // step 2:
      // we create a writer that listens to the document
      PdfWriter.getInstance(document,
          new GfrFileOutputStream("com.lowagie.examples.fonts.FontFactoryType1Fonts.pdf"));

      // step 3: we open the document
      document.open();
      // step 4:
     
      // the 14 standard fonts in PDF
      LwgFont[] fonts = new LwgFont[14];
      fonts[0] = FontFactory.getFont(FontFactory.COURIER, LwgFont.DEFAULTSIZE, LwgFont.NORMAL);
            fonts[1] = FontFactory.getFont(FontFactory.COURIER, LwgFont.DEFAULTSIZE, LwgFont.ITALIC);
            fonts[2] = FontFactory.getFont(FontFactory.COURIER, LwgFont.DEFAULTSIZE, LwgFont.BOLD);
            fonts[3] = FontFactory.getFont(FontFactory.COURIER, LwgFont.DEFAULTSIZE, LwgFont.BOLD | LwgFont.ITALIC);
            fonts[4] = FontFactory.getFont(FontFactory.HELVETICA, LwgFont.DEFAULTSIZE, LwgFont.NORMAL);
            fonts[5] = FontFactory.getFont(FontFactory.HELVETICA, LwgFont.DEFAULTSIZE, LwgFont.ITALIC);
            fonts[6] = FontFactory.getFont(FontFactory.HELVETICA, LwgFont.DEFAULTSIZE, LwgFont.BOLD);
            fonts[7] = FontFactory.getFont(FontFactory.HELVETICA, LwgFont.DEFAULTSIZE, LwgFont.BOLDITALIC);
            fonts[8] = FontFactory.getFont(FontFactory.TIMES_ROMAN, LwgFont.DEFAULTSIZE, LwgFont.NORMAL);
            fonts[9] = FontFactory.getFont(FontFactory.TIMES_ROMAN, LwgFont.DEFAULTSIZE, LwgFont.ITALIC);
            fonts[10] = FontFactory.getFont(FontFactory.TIMES_ROMAN, LwgFont.DEFAULTSIZE, LwgFont.BOLD);
            fonts[11] = FontFactory.getFont(FontFactory.TIMES_ROMAN, LwgFont.DEFAULTSIZE, LwgFont.BOLDITALIC);
            fonts[12] = FontFactory.getFont(FontFactory.SYMBOL, LwgFont.DEFAULTSIZE, LwgFont.NORMAL);
            fonts[13] = FontFactory.getFont(FontFactory.ZAPFDINGBATS, LwgFont.DEFAULTSIZE, LwgFont.NORMAL);
      // add the content
      for (int i = 0; i < 14; i++) {
          document.add(new Paragraph("quick brown fox jumps over the lazy dog", fonts[i]));
      }
    } 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("Encodings");
       
        // step 1: creation of a document-object
        LwgDocument document = new LwgDocument();
       
        try {
           
            // step 2: creation of the writer
            PdfWriter.getInstance(document, new GfrFileOutputStream("com.lowagie.examples.fonts.FontEncoding.pdf"));
           
            // step 3: we open the document
            document.open();
           
            // step 4: we add content to the document
            BaseFont helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
            LwgFont font = new LwgFont(helvetica, 12, LwgFont.NORMAL);
            Chunk chunk = new Chunk("Sponsor this example and send me 1\u20ac. These are some special characters: \u0152\u0153\u0160\u0161\u0178\u017D\u0192\u02DC\u2020\u2021\u2030", font);
            document.add(chunk);
        }
        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("Simple single object columns");
       
        // step 1: creation of a document-object
        LwgDocument document = new LwgDocument();
       
        try {
           
            // step 2: creation of the writer
            PdfWriter writer = PdfWriter.getInstance(document, new GfrFileOutputStream("com.lowagie.examples.objects.columns.Column.pdf"));
           
            // step 3: we open the document
            document.open();
           
            // step 4:
           
            // we create some content
            BaseFont bf = BaseFont.createFont(BaseFont.COURIER, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
            LwgFont font = new LwgFont(bf, 11, LwgFont.NORMAL);
           
            LwgPhrase unicodes = new LwgPhrase(15, "UNI\n", font);
            LwgPhrase characters = new LwgPhrase(15, "\n", font);
            LwgPhrase names = new LwgPhrase(15, "NAME\n", font);
           
            for (int i = 0; i < 27; i++) {
                unicodes.add(uni[i] + "\n");
                characters.add(code[i] + "\n");
                names.add(name[i] + "\n");
            }
           
            // we grab the ContentByte and do some stuff with it
            PdfContentByte cb = writer.getDirectContent();
           
            ColumnText ct = new ColumnText(cb);
            ct.setSimpleColumn(unicodes, 60, 300, 100, 300 + 28 * 15, 15, LwgElement.ALIGN_CENTER);
            ct.go();
            cb.rectangle(103, 295, 52, 8 + 28 * 15);
            cb.stroke();
            ct.setSimpleColumn(characters, 105, 300, 150, 300 + 28 * 15, 15, LwgElement.ALIGN_RIGHT);
            ct.go();
            ct.setSimpleColumn(names, 160, 300, 500, 300 + 28 * 15, 15, LwgElement.ALIGN_LEFT);
            ct.go();
           
        }
        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("the Paragraph object (2)");

    // step 1: creation of a document-object
    LwgDocument document = new LwgDocument();
    try {
      // step 2:
      // we create a writer that listens to the document
      PdfWriter.getInstance(document, new FileOutputStream("ParagraphAttributes.pdf"));

      // step 3: we open the document
      document.open();
      // step 4:
      Paragraph[] p = new Paragraph[5];
            p[0] = 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.");
            p[1] = 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.]");
            p[2] = 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.");
            p[3] = 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.");
            p[4] = 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.");
            for (int i = 0; i < 5; i++) {
              p[i].setAlignment(LwgElement.ALIGN_JUSTIFIED);
              document.add(p[i]);
            }
            document.newPage();
            for (int i = 0; i < 5; i++) {
              p[i].setAlignment(LwgElement.ALIGN_JUSTIFIED);
              p[i].setIndentationLeft(i * 15f);
              p[i].setIndentationRight((5 - i) * 15f);
              document.add(p[i]);
            }
            document.newPage();
            for (int i = 0; i < 5; i++) {
              p[i].setAlignment(LwgElement.ALIGN_RIGHT);
              p[i].setSpacingAfter(15f);
              document.add(p[i]);
            }
            for (int i = 0; i < 5; i++) {
              p[i].setAlignment(LwgElement.ALIGN_LEFT);
              p[i].setSpacingBefore(15f);
              document.add(p[i]);
            }
            for (int i = 0; i < 5; i++) {
              p[i].setAlignment(LwgElement.ALIGN_CENTER);
              p[i].setSpacingAfter(15f);
              p[i].setSpacingBefore(15f);
              document.add(p[i]);
            }
            document.newPage();
    } 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("pagelabels");

    // step 1: creation of a document-object
    LwgDocument document = new LwgDocument();
    try {
            // step 2:
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("PageLabels.pdf"));
            // step 3:
            writer.setViewerPreferences(PdfWriter.PageModeUseThumbs);
            document.open();
            // step 4:
            // we add some content
            for (int k = 1; k <= 10; ++k) {
                document.add(new Paragraph("This document has the logical page numbers: i,ii,iii,iv,1,2,3,A-8,A-9,A-10\nReal page " + k));
                document.newPage();
            }
            PdfPageLabels pageLabels = new PdfPageLabels();
            pageLabels.addPageLabel(1, PdfPageLabels.LOWERCASE_ROMAN_NUMERALS);
            pageLabels.addPageLabel(5, PdfPageLabels.DECIMAL_ARABIC_NUMERALS);
            pageLabels.addPageLabel(8, PdfPageLabels.DECIMAL_ARABIC_NUMERALS, "A-", 8);
            writer.setPageLabels(pageLabels);
    } 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("Hello World! example for the RTF format");
        try {
            // Step 1: Create a new Document
            LwgDocument document = new LwgDocument();
           
            // Step 2: Create a new instance of the RtfWriter2 with the document
            //         and target output stream.
            RtfWriter2.getInstance(document, new FileOutputStream("HelloWorld.rtf"));
           
            // Step 3: Open the document.
            document.open();
           
            // Step 4: Add content to the document.
            document.add(new Paragraph("Hello World!"));
           
            // Step 5: Close the document. It will be written to the target output stream.
            document.close();
        } catch (FileNotFoundException fnfe) {
            // It might not be possible to create the target file.
            fnfe.printStackTrace();
        } catch (DocumentException de) {
            // DocumentExceptions arise if you add content to the document before opening or
View Full Code Here

     * @param args Unused
     */
    public static void main(String[] args) {
        System.out.println("Demonstrates using the paragraph stylesheets");
        try {
            LwgDocument document = new LwgDocument();
            RtfWriter2.getInstance(document, new FileOutputStream("BasicStylesheets.rtf"));

            document.open();
           
            // Simply set the stylesheet you wish to use as the Font
            // of the Paragraph
            document.add(new Paragraph("This is a heading",
                    RtfParagraphStyle.STYLE_HEADING_1));
           
            document.add(new Paragraph("Just some text that is formatted " +
                    "in the default style.", RtfParagraphStyle.STYLE_NORMAL));

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

     * @param args Unused
     */
    public static void main(String[] args) {
        System.out.println("Demonstrates how to use the RtfTabGroup to repeatedly add a set of tab stops");
        try {
            LwgDocument document = new LwgDocument();
            RtfWriter2.getInstance(document, new FileOutputStream("TabGroups.rtf"));

            document.open();
           
            // Construct the RtfTabGroup object
            RtfTabGroup tabGroup = new RtfTabGroup();
            // Add RtfTab tab stops at the desired positions
            tabGroup.add(new RtfTab(400, RtfTab.TAB_RIGHT_ALIGN));
            tabGroup.add(new RtfTab(500, RtfTab.TAB_DECIMAL_ALIGN));
           
            // Create a Paragraph object
            Paragraph par = new Paragraph();
            // Add the tab group to the paragraph
            par.add(tabGroup);
            // Specify the tab positions using "\t"
            par.add("Description\tDate\tAmount");
            document.add(par);
           
            DecimalFormat nf = new DecimalFormat("#.00");
            double sum = 0;
            for(int i = 0; i < 10; i++) {
                double value = Math.random() * 100;
                sum = sum + value;

                par = new Paragraph();
                // The RtfTabGroup can be reused for further paragraphs
                par.add(tabGroup);
                par.add("Item " + (i + 1) + "\t" + (12 + i) + ".03.2007\t" + nf.format(value));
                document.add(par);
            }

            par = new Paragraph("", new LwgFont(LwgFont.TIMES_ROMAN, 12, LwgFont.BOLD));
            par.add(tabGroup);
            // If a tab in the RtfTabGroup is not needed, just add an empty tab stop in the text
            par.add("Total\t\t" + nf.format(sum));
            document.add(par);
           
            document.close();
        } catch (FileNotFoundException fnfe) {
            fnfe.printStackTrace();
        } catch (DocumentException de) {
            de.printStackTrace();
        }
View Full Code Here

     * @param args Unused
     */
    public static void main(String[] args) {
        System.out.println("Demonstrates using changing the properties of paragraph stylesheets");
        try {
            LwgDocument document = new LwgDocument();
            RtfWriter2.getInstance(document, new FileOutputStream("ChangingStylesheets.rtf"));

            // Set the default style font name. This is inherited
            // by all other styles.
            RtfParagraphStyle.STYLE_NORMAL.setFontName("Times New Roman");
            // Set the colour of the level 1 heading to blue.
            RtfParagraphStyle.STYLE_HEADING_1.setColor(Color.BLUE);
            // Set the font name of the heading back to Arial again.
            RtfParagraphStyle.STYLE_HEADING_2.setFontName("Arial");
            // Change the font size
            RtfParagraphStyle.STYLE_HEADING_2.setSize(12);

            // Change the style properties to the desired values
            // before document.open()

            document.open();
           
            // Simply set the stylesheet you wish to use as the Font
            // of the Paragraph
            document.add(new Paragraph("This is a heading level 1",
                    RtfParagraphStyle.STYLE_HEADING_1));
            document.add(new Paragraph("This is a heading level 2",
                    RtfParagraphStyle.STYLE_HEADING_2));
            document.add(new Paragraph("Just some text that is formatted " +
                    "in the default style.", RtfParagraphStyle.STYLE_NORMAL));

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

     * @param args Unused
     */
    public static void main(String[] args) {
        System.out.println("Demonstrates use of the RtfHeaderFooter for extended headers and footers");
        try {
            LwgDocument document = new LwgDocument();
            RtfWriter2.getInstance(document, new FileOutputStream("ExtendedHeaderFooter.rtf"));

            // Create the Paragraphs that will be used in the header.
            Paragraph date = new Paragraph("01.01.2010");
            date.setAlignment(Paragraph.ALIGN_RIGHT);
            Paragraph address = new Paragraph("TheFirm\nTheRoad 24, TheCity\n" +
                    "+00 99 11 22 33 44");

            // Create the RtfHeaderFooter with an array containing the Paragraphs to add
            RtfHeaderFooter header = new RtfHeaderFooter(new LwgElement[]{date, address});
           
            // Set the header
            document.setHeader(header);

            // Create the table that will be used as the footer
            Table footer = new Table(2);
            footer.setBorder(0);
            footer.getDefaultCell().setBorder(0);
            footer.setWidth(100);
            footer.addCell(new LwgCell("(c) Mark Hall"));
            Paragraph pageNumber = new Paragraph("Page ");
           
            // The RtfPageNumber is an RTF specific element that adds a page number field
            pageNumber.add(new RtfPageNumber());
            pageNumber.setAlignment(Paragraph.ALIGN_RIGHT);
            footer.addCell(new LwgCell(pageNumber));
           
            // Create the RtfHeaderFooter and set it as the footer to use
            document.setFooter(new RtfHeaderFooter(footer));
           
            document.open();
           
            document.add(new Paragraph("This document has headers and footers created" +
                    " using the RtfHeaderFooter class."));

            document.close();
        } catch (FileNotFoundException fnfe) {
            fnfe.printStackTrace();
        } catch (DocumentException 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.