Package com.lowagie.text

Examples of com.lowagie.text.LwgDocument


      img.scalePercent(this.scaleX.floatValue(), this.scaleY.floatValue());
      //        img.setBorder(value);

      try {
        if (this.rtfParser.isImport()) {
          LwgDocument doc = this.rtfParser.getDocument();
          doc.add(img);
//          RtfDocument rtfDoc = this.rtfParser.getRtfDocument();
//          RtfImage rtfImage = new RtfImage(rtfDoc, img);
//          rtfDoc.add(rtfImage);
        }
        if (this.rtfParser.isConvert()) {
View Full Code Here


  public static void main(String[] args) {

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

    // 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.StandardType1Fonts.pdf"));

      // step 3: we open the document
      document.open();
      // step 4:
     
      // the 14 standard fonts in PDF: do not use this Font constructor!
      // this is for demonstration purposes only, use FontFactory!
      LwgFont[] fonts = new LwgFont[14];
      fonts[0] = new LwgFont(LwgFont.COURIER, LwgFont.DEFAULTSIZE, LwgFont.NORMAL);
      fonts[1] = new LwgFont(LwgFont.COURIER, LwgFont.DEFAULTSIZE, LwgFont.ITALIC);
      fonts[2] = new LwgFont(LwgFont.COURIER, LwgFont.DEFAULTSIZE, LwgFont.BOLD);
      fonts[3] = new LwgFont(LwgFont.COURIER, LwgFont.DEFAULTSIZE, LwgFont.BOLD | LwgFont.ITALIC);
      fonts[4] = new LwgFont(LwgFont.HELVETICA, LwgFont.DEFAULTSIZE, LwgFont.NORMAL);
      fonts[5] = new LwgFont(LwgFont.HELVETICA, LwgFont.DEFAULTSIZE, LwgFont.ITALIC);
      fonts[6] = new LwgFont(LwgFont.HELVETICA, LwgFont.DEFAULTSIZE, LwgFont.BOLD);
      fonts[7] = new LwgFont(LwgFont.HELVETICA, LwgFont.DEFAULTSIZE, LwgFont.BOLDITALIC);
      fonts[8] = new LwgFont(LwgFont.TIMES_ROMAN, LwgFont.DEFAULTSIZE, LwgFont.NORMAL);
      fonts[9] = new LwgFont(LwgFont.TIMES_ROMAN, LwgFont.DEFAULTSIZE, LwgFont.ITALIC);
      fonts[10] = new LwgFont(LwgFont.TIMES_ROMAN, LwgFont.DEFAULTSIZE, LwgFont.BOLD);
      fonts[11] = new LwgFont(LwgFont.TIMES_ROMAN, LwgFont.DEFAULTSIZE, LwgFont.BOLDITALIC);
      fonts[12] = new LwgFont(LwgFont.SYMBOL);
      fonts[13] = new LwgFont(LwgFont.ZAPFDINGBATS);
      // 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("Open Application");

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

    try {

      // step 2:
      HtmlWriter.getInstance(document, new FileOutputStream(
          "JavaScriptAction.html"));
      // step 3: we add Javascript as Metadata and we open the document
     
      StringBuffer javaScriptSection = new StringBuffer();
            javaScriptSection.append("\t\tfunction load() {\n");
            javaScriptSection.append("\t\t  alert('Page has been loaded.');\n");
            javaScriptSection.append("\t\t}\n");
         
            javaScriptSection.append("\t\tfunction unload(){\n");
            javaScriptSection.append("\t\t  alert('Page has been unloaded.');\n");
            javaScriptSection.append("\t\t}\n");

            javaScriptSection.append("\t\tfunction sayHi(){\n");
            javaScriptSection.append("\t\t  alert('Hi !!!');\n");
            javaScriptSection.append("\t\t}");

            document.add(new Header(HtmlTags.JAVASCRIPT, javaScriptSection.toString()));
            document.setJavaScript_onLoad  ("load()");
            document.setJavaScript_onUnLoad("unload()");
           
      document.open();
      // step 4: we add some content
      LwgPhrase phrase1 = new LwgPhrase("There are 3 JavaScript functions in the HTML page, load(), unload() and sayHi().\n\n" +
                                   "The first one will be called when the HTML page has been loaded by your browser.\n" +
                                   "The second one will be called when the HTML page is being unloaded,\n" +
                                   "for example when you go to another page.\n");
              document.add(phrase1);

            // add a HTML link <A HREF="...">
              Anchor anchor = new Anchor("Click here to execute the third JavaScript function.");
              anchor.setReference("JavaScript:sayHi()");
              document.add(anchor);

    } 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("Test Suite");

        try {
            LwgDocument doc = new LwgDocument();
            RtfWriter2 writer2 = RtfWriter2.getInstance(doc,
                    new FileOutputStream("testNew.rtf"));

            writer2.setAutogenerateTOCEntries(true);

            Table headerTable = new Table(3);
            headerTable.addCell("Test Cell 1");
            headerTable.addCell("Test Cell 2");
            headerTable.addCell("Test Cell 3");
            HeaderFooter header = new RtfHeaderFooter(headerTable);
            RtfHeaderFooterGroup footer = new RtfHeaderFooterGroup();
            footer
                    .setHeaderFooter(
                            new RtfHeaderFooter(new LwgPhrase(
                                    "This is the footer on the title page")),
                            com.lowagie.text.rtf.headerfooter.RtfHeaderFooter.DISPLAY_FIRST_PAGE);
            footer
                    .setHeaderFooter(
                            new RtfHeaderFooter(new LwgPhrase(
                                    "This is a left side page")),
                            com.lowagie.text.rtf.headerfooter.RtfHeaderFooter.DISPLAY_LEFT_PAGES);
            footer
                    .setHeaderFooter(
                            new RtfHeaderFooter(new LwgPhrase(
                                    "This is a right side page")),
                            com.lowagie.text.rtf.headerfooter.RtfHeaderFooter.DISPLAY_RIGHT_PAGES);

            doc.setHeader(header);
            doc.setFooter(footer);

            doc.open();

            Paragraph p = new Paragraph();
            p.add(new RtfTableOfContents("UPDATE ME!"));
            doc.add(p);

            p = new Paragraph("", new RtfFont("Staccato222 BT"));
            p.add(new Chunk("Hello! "));
            p.add(new Chunk("How do you do?"));
            doc.add(p);
            p.setAlignment(LwgElement.ALIGN_RIGHT);
            doc.add(p);

            Anchor a = new Anchor("http://www.uni-klu.ac.at");
            a.setReference("http://www.uni-klu.ac.at");
            doc.add(a);

            LwgImage img = LwgImage.getInstance("pngnow.png");
            doc.add(new Chunk(img, 0, 0));
            doc.add(new Annotation("Mark", "This works!"));

            Chunk c = new Chunk("");
            c.setNewPage();
            doc.add(c);

            List subList = new List(true, 40);
            subList.add(new ListItem("Sub list 1"));
            subList.add(new ListItem("Sub list 2"));

            List list = new List(true, 20);
            list.add(new ListItem("Test line 1"));
            list
                    .add(new ListItem(
                            "Test line 2 - This is a really long test line to test that linebreaks are working the way they are supposed to work so a really really long line of drivel is required"));
            list.add(subList);
            list.add(new ListItem("Test line 3 - \t\u20ac\t 60,-"));
            doc.add(list);

            list = new List(false, 20);
            list.add(new ListItem("Bullet"));
            list.add(new ListItem("Another one"));
            doc.add(list);

            doc.newPage();

            Chapter chapter = new Chapter(new Paragraph("This is a Chapter"), 1);
            chapter.add(new Paragraph(
                    "This is some text that belongs to this chapter."));
            chapter.add(new Paragraph("A second paragraph. What a surprise."));

            Section section = chapter.addSection(new Paragraph(
                    "This is a subsection"));
            section.add(new Paragraph("Text in the subsection."));

            doc.add(chapter);

            com.lowagie.text.rtf.field.RtfTOCEntry rtfTOC = new com.lowagie.text.rtf.field.RtfTOCEntry(
                    "Table Test");
            doc.add(rtfTOC);

            Table table = new Table(3);
            table.setPadding(2);
            table.setAlignment(LwgElement.ALIGN_LEFT);
            table.setSpacing(2);

            LwgCell emptyCell = new LwgCell("");

            LwgCell cellLeft = new LwgCell("Left Alignment");
            cellLeft.setHorizontalAlignment(LwgElement.ALIGN_LEFT);
            LwgCell cellCenter = new LwgCell("Center Alignment");
            cellCenter.setHorizontalAlignment(LwgElement.ALIGN_CENTER);
            LwgCell cellRight = new LwgCell("Right Alignment");
            cellRight.setHorizontalAlignment(LwgElement.ALIGN_RIGHT);

            table.addCell(cellLeft);
            table.addCell(cellCenter);
            table.addCell(cellRight);

            LwgCell cellSpanHoriz = new LwgCell("This Cell spans two columns");
            cellSpanHoriz.setColspan(2);
            table.addCell(cellSpanHoriz);
            table.addCell(emptyCell);

            LwgCell cellSpanVert = new LwgCell("This Cell spans two rows");
            cellSpanVert.setRowspan(2);
            table.addCell(emptyCell);
            table.addCell(cellSpanVert);
            table.addCell(emptyCell);
            table.addCell(emptyCell);
            table.addCell(emptyCell);

            LwgCell cellSpanHorizVert = new LwgCell(
                    "This Cell spans both two columns and two rows");
            cellSpanHorizVert.setColspan(2);
            cellSpanHorizVert.setRowspan(2);
            table.addCell(emptyCell);
            table.addCell(cellSpanHorizVert);
            table.addCell(emptyCell);

            RtfCell cellDotted = new RtfCell("Dotted border");
            cellDotted.setBorders(new RtfBorderGroup(LwgRectangle.BOX,
                    RtfBorder.BORDER_DOTTED, 1, new Color(0, 0, 0)));
            RtfCell cellEmbossed = new RtfCell("Embossed border");
            cellEmbossed.setBorders(new RtfBorderGroup(LwgRectangle.BOX,
                    RtfBorder.BORDER_EMBOSS, 1, new Color(0, 0, 0)));
            RtfCell cellNoBorder = new RtfCell("No border");
            cellNoBorder.setBorders(new RtfBorderGroup());

            table.addCell(cellDotted);
            table.addCell(cellEmbossed);
            table.addCell(cellNoBorder);

            doc.add(table);

            for (int i = 0; i < 300; i++) {
                doc.add(new Paragraph(
                        "Dummy line to get multi-page document. Line "
                                + (i + 1)));
            }

            doc.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
View Full Code Here

    public static void main(String[] args) {
       
        System.out.println("True Type fonts (not embedded)");
       
        // 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.getInstance(document, new GfrFileOutputStream("com.lowagie.examples.fonts.TrueType.pdf"));
           
            // step 3: we open the document
            document.open();
           
            // step 4: we add content to the document
            BaseFont bfComic = BaseFont.createFont("c:\\windows\\fonts\\comicbd.ttf", BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
            LwgFont font = new LwgFont(bfComic, 12);
            String text1 = "This is the quite popular True Type font 'Comic'.";
            document.add(new Paragraph(text1, font));
        }
        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("Metadata");

    // 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
      HtmlWriter.getInstance(document,
          new FileOutputStream("HelloWorldMeta.html"));

      // step 3: we add some metadata open the document
      // standard meta information
      document.addTitle("Hello World example");
            document.addAuthor("Bruno Lowagie");
            document.addSubject("This example explains step 3 in Chapter 1");
            document.addKeywords("Metadata, iText, step 3, tutorial");
            // custom (HTML) meta information
            document.addHeader("Expires", "0");
            // meta information that will be in a comment section in HTML
            document.addCreator("My program using iText");
      document.open();
      // step 4: we add a paragraph to the document
      document.add(new Paragraph("Hello World"));
    } 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");
        try {
          // step 1
            LwgDocument document = new LwgDocument(LwgPageSize.A4, 50, 50, 50, 50);
            // step 2
            PdfWriter.getInstance(document, new GfrFileOutputStream("com.lowagie.examples.fonts.EncodingFont.pdf"));
            // step 3
            document.open();
            // step 4
            String all[] = {"Symbol", "ZapfDingbats"};
            LwgFont hex = new LwgFont(LwgFont.HELVETICA, 5);
            for (int z = 0; z < all.length; ++z) {
                String file = all[z];
                document.add(new Paragraph("Unicode equivalence for the font \""
                    + file
            +"\" with the encoding \""
            +file
            + "\"\n"));
                char tb[];
                if (z == 0)
                    tb = SYMBOL_TABLE;
                else
                    tb = DINGBATS_TABLE;
                BaseFont bf;
                bf = BaseFont.createFont(file, file, true);
                LwgFont f = new LwgFont(bf, 12);
                LwgPdfPTable table = new LwgPdfPTable(16);
                table.setWidthPercentage(100);
                table.getDefaultCell().setBorderWidth(1);
                table.getDefaultCell().setHorizontalAlignment(LwgElement.ALIGN_CENTER);
                for (int k = 0; k < tb.length; ++k) {
                    char c = tb[k];
                    if (bf.charExists(c)) {
                        LwgPhrase ph = new LwgPhrase(12, new String(new char[]{c}), f);
                        ph.add(new LwgPhrase(12, "\n\n" + cst(c), hex));
                        table.add(ph);
                    }
                    else {
                        LwgPhrase ph = new LwgPhrase("\u00a0");
                        ph.add(new LwgPhrase(12, "\n\n" + cst(c), hex));
                        table.add(ph);
                    }
                }
                document.add(table);
                document.newPage();
            }
            // step 5
            document.close();
        }
        catch (Exception de) {
            de.printStackTrace();
        }
  }
View Full Code Here

     * @param args no arguments needed
     */
    public static void main(String[] args) {
      System.out.println("Space Word Ratio");
      // step 1
        LwgDocument document = new LwgDocument(LwgPageSize.A4, 50, 350, 50, 50);
        try {
          // step 2
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("spacewordratio.pdf"));
            // step 3
            document.open();
            // step 4
            String text = "Flanders International Filmfestival Ghent - Internationaal Filmfestival van Vlaanderen Gent";
            Paragraph p = new Paragraph(text);
            p.setAlignment(LwgElement.ALIGN_JUSTIFIED);
            document.add(p);
            document.newPage();
            writer.setSpaceCharRatio(PdfWriter.NO_SPACE_CHAR_RATIO);
            document.add(p);
        }
        catch (Exception de) {
            de.printStackTrace();
        }
        // step 5
        document.close();
    }
View Full Code Here

    public static void main(String[] args) {
       
        System.out.println("Images with complete URL");
       
        // 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
            HtmlWriter.getInstance(document, new FileOutputStream("images.html"));
           
            // step 3: we open the document
            document.open();
           
            // step 4:
            document.add(new Paragraph("A picture of my dog: otsoe.jpg"));
            LwgImage jpg = LwgImage.getInstance(new URL("/examples/com/lowagie/examples/html/otsoe.jpg"));
            document.add(jpg);
            document.add(new Paragraph("getacro.gif"));
            LwgImage gif= LwgImage.getInstance(new URL("/examples/com/lowagie/examples/html/getacro.gif"));
            document.add(gif);
            document.add(new Paragraph("pngnow.png"));
            LwgImage png = LwgImage.getInstance(new URL("/examples/com/lowagie/examples/html/pngnow.png"));
            document.add(png);
            document.add(new Paragraph("iText.bmp"));
            LwgImage bmp = LwgImage.getInstance(new URL("/examples/com/lowagie/examples/html/iText.bmp"));
            document.add(bmp);
            document.add(new Paragraph("iText.wmf"));
            LwgImage wmf = LwgImage.getInstance(new URL("/examples/com/lowagie/examples/html/iText.wmf"));
            document.add(wmf);
            document.add(new Paragraph("iText.tif"));
            LwgImage tiff = LwgImage.getInstance(new URL("/examples/com/lowagie/examples/html/iText.tif"));
            document.add(tiff);
        }
        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");

    // 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("Paragraphs.pdf"));

      // step 3: we open the document
      document.open();
      // step 4:
      Paragraph p1 = new Paragraph(new Chunk(
          "This is my first paragraph. ",
          FontFactory.getFont(FontFactory.HELVETICA, 10)));
      p1.add("The leading of this paragraph is calculated automagically. ");
      p1.add("The default leading is 1.5 times the fontsize. ");
      p1.add(new Chunk("You can add chunks "));
      p1.add(new LwgPhrase("or you can add phrases. "));
      p1.add(new LwgPhrase(
        "Unless you change the leading with the method setLeading, the leading doesn't change if you add text with another leading. This can lead to some problems.",
        FontFactory.getFont(FontFactory.HELVETICA, 18)));
      document.add(p1);
      Paragraph p2 = new Paragraph(new LwgPhrase(
          "This is my second paragraph. ", FontFactory.getFont(
              FontFactory.HELVETICA, 12)));
      p2.add("As you can see, it started on a new line.");
      document.add(p2);
      Paragraph p3 = new Paragraph("This is my third paragraph.",
          FontFactory.getFont(FontFactory.HELVETICA, 12));
      document.add(p3);
    } 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

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.