Package com.lowagie.text

Examples of com.lowagie.text.LwgDocument


     * Demonstrates the use of PageEvents.
     * @param args no arguments needed
     */
    public static void main(String[] args)
    {
        LwgDocument document = new LwgDocument(LwgPageSize.A4, 50, 50, 70, 70);
        try {
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("endpage.pdf"));
            writer.setPageEvent(new EndPage());
            document.open();
            String text = "Lots of text. ";
            for (int k = 0; k < 10; ++k)
                text += text;
            document.add(new Paragraph(text));
            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("Transparency Groups");
        // step 1: creation of a document-object
        LwgDocument document = new LwgDocument(LwgPageSize.A4, 50, 50, 50, 50);
        try {
            // step 2: creation of a writer
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("groups.pdf"));
            // step 3: we open the document
            document.open();
            // step 4: content
            PdfContentByte cb = writer.getDirectContent();
            float gap = (document.getPageSize().getWidth() - 400) / 3;
           
            pictureBackdrop(gap, 500, cb);
            pictureBackdrop(200 + 2 * gap, 500, cb);
            pictureBackdrop(gap, 500 - 200 - gap, cb);
            pictureBackdrop(200 + 2 * gap, 500 - 200 - gap, cb);

            PdfTemplate tp;
            PdfTransparencyGroup group;
           
            tp = cb.createTemplate(200, 200);
            pictureCircles(0, 0, tp);
            group = new PdfTransparencyGroup();
            group.setIsolated(true);
            group.setKnockout(true);
            tp.setGroup(group);
            tp.sanityCheck();
            cb.addTemplate(tp, gap, 500);

           
            tp = cb.createTemplate(200, 200);
            pictureCircles(0, 0, tp);
            group = new PdfTransparencyGroup();
            group.setIsolated(true);
            group.setKnockout(false);
            tp.setGroup(group);
            tp.sanityCheck();
            cb.addTemplate(tp, 200 + 2 * gap, 500);

           
            tp = cb.createTemplate(200, 200);
            pictureCircles(0, 0, tp);
            group = new PdfTransparencyGroup();
            group.setIsolated(false);
            group.setKnockout(true);
            tp.setGroup(group);
            tp.sanityCheck();
            cb.addTemplate(tp, gap, 500 - 200 - gap);

           
            tp = cb.createTemplate(200, 200);
            pictureCircles(0, 0, tp);
            group = new PdfTransparencyGroup();
            group.setIsolated(false);
            group.setKnockout(false);
            tp.setGroup(group);
            tp.sanityCheck();
            cb.addTemplate(tp, 200 + 2 * gap, 500 - 200 - gap);

            cb.sanityCheck();
        }
        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("iText version " + LwgDocument.getVersion());       
        // 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 FileOutputStream("version.pdf"));
           
            // step 3: we open the document
            document.open();
           
            // step 4:
            document.add(new Paragraph("This page was made using " + LwgDocument.getVersion()));
        }
        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("Painting Patterns");
       
        // 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("patterns.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();
           
            BaseFont bf = BaseFont.createFont("Times-Roman", "winansi", false);
           
            // step 5: we create some PdfPatternPainter instances for drawing path, text, or placing image
           
            // LwgImage instance to be placed in PdfPatternPainter canvas. Any nice one?
            LwgImage img = LwgImage.getInstance("pngnow.png");

            PdfPatternPainter p = cb.createPattern(60f, 60f, 60f, 60f);
            PdfPatternPainter p1 = cb.createPattern(60f, 60f, 60f, 60f);
            PdfPatternPainter p2 = cb.createPattern(img.getScaledWidth(), img.getScaledHeight(), img.getScaledWidth(), img.getScaledHeight());
           
           
            // step 6: put your drawing instruction in the painter canvas
           
            // A star pattern taken from Adobe PDF Reference Book p.207
            String star = "0.3 g\n15.000 27.000 m\n"
            + "7.947 5.292 l\n26.413 18.708 l\n"
            + "3.587 18.708 l\n22.053 5.292 l\nf\n"
            + "45.000 57.000 m\n37.947 35.292 l\n"
            + "56.413 48.708 l\n33.587 48.708 l\n"
            + "52.053 35.292 l\nf\n"
            + "0.7 g\n15.000 57.000 m\n"
            + "7.947 35.292 l\n26.413 48.708 l\n"
            + "3.587 48.708 l\n22.053 35.292 l\nf\n"
            + "45.000 27.000 m\n37.947 5.292 l\n"
            + "56.413 18.708 l\n33.587 18.708 l\n"
            + "52.053 5.292 l\nf";
           
            p.setLiteral(star);
           
            // A Pattern with some text drawing
            p1.setGrayFill(0.3f);
            p1.setFontAndSize(bf, 12);
            p1.beginText();
            p1.setTextMatrix(1f, 0f, 0f, 1f, 0f, 0f);
            p1.showText("A B C D");
            p1.endText();
            p1.moveTo(0f, 0f);
            p1.lineTo(60f, 60f);
            p1.stroke();
            p1.sanityCheck();
           
            // A pattern with an image and position
            p2.addImage(img, img.getScaledWidth(), 0f, 0f, img.getScaledHeight(), 0f, 0f);
            p2.setPatternMatrix(1f, 0f, 0f, 1f, 60f, 60f);
            p2.sanityCheck();
           
            // See if we can apply the pattern color to chunk, phrase or paragraph
            PatternColor pat = new PatternColor(p);
            PatternColor pat1 = new PatternColor(p1);
            PatternColor pat2 = new PatternColor(p2);
            String text = "Text with pattern";
            document.add(new Paragraph(text, FontFactory.getFont(FontFactory.HELVETICA, 60, LwgFont.BOLD, new GrayColor(0.3f))));
            document.add(new Paragraph(text, FontFactory.getFont(FontFactory.HELVETICA, 60, LwgFont.BOLD, pat)));
           
            // draw a rectangle filled with star pattern
            cb.setPatternFill(p);
            cb.setGrayStroke(0.0f);
            cb.rectangle(20, 20, 284, 120);
            cb.fillStroke();
           
            // draw some characters filled with star.
            // Note: A gray, rgb, cmyk or spot color should be applied first
            // otherwise, you will not be able to see the character glyph
            // since the glyph path is filled by pattern
            cb.beginText();
            cb.setFontAndSize(bf, 1);
            cb.setTextMatrix(270f, 0f, 0f, 270f, 20f, 100f);
            cb.setGrayFill(0.9f);
            cb.showText("ABC");
            cb.setPatternFill(p);
            cb.moveTextWithLeading(0.0f, 0.0f);
            cb.showText("ABC");
            cb.endText();
            cb.setPatternFill(p);
           
            // draw a circle. Similar to rectangle
            cb.setGrayStroke(0.0f);
            cb.circle(150f, 400f, 150f);
            cb.fillStroke();
           
            // New Page to draw text in the pattern painter's canvas
            document.newPage();
           
            document.add(new Paragraph(text, FontFactory.getFont(FontFactory.HELVETICA, 60, LwgFont.BOLD, new GrayColor(0.3f))));
            document.add(new Paragraph(text, FontFactory.getFont(FontFactory.HELVETICA, 60, LwgFont.BOLD, pat1)));
            // draw a rectangle
            cb.setPatternFill(p1);
            cb.setGrayStroke(0.0f);
            cb.rectangle(0, 0, 284, 120);
            cb.fillStroke();
           
            // draw some characters
            cb.beginText();
            cb.setFontAndSize(bf, 1);
            cb.setTextMatrix(270f, 0f, 0f, 270f, 20f, 100f);
            cb.setGrayFill(0.9f);
            cb.showText("ABC");
            cb.setPatternFill(p1);
            cb.moveTextWithLeading(0.0f, 0.0f);
            cb.showText("ABC");
            cb.endText();
           
            // draw a circle
            cb.setPatternFill(p1);
            cb.setGrayStroke(0.0f);
            cb.circle(150f, 400f, 150f);
            cb.fillStroke();
            cb.sanityCheck();
           
            // New page to place image in the pattern painter's canvas
            document.newPage();
            document.add(new Paragraph(text, FontFactory.getFont(FontFactory.HELVETICA, 60, LwgFont.BOLD, new GrayColor(0.3f))));
            document.add(new Paragraph(text, FontFactory.getFont(FontFactory.HELVETICA, 60, LwgFont.BOLD, pat2)));
            // The original LwgImage for comparison reason.
            // Note: The width and height is the same as bbox in pattern
            cb.addImage(img, img.getScaledWidth(), 0f, 0f, img.getScaledHeight(), 350f, 400f);
           
            // draw a rectangle
            cb.setPatternFill(p2);
            cb.setGrayStroke(0.0f);
            cb.rectangle(60, 60, 300, 120);
            cb.fillStroke();
           
            // draw some characters.
            // Note: if the image fills up the pattern, there's no need to draw text twice
            // since colors in image will be clipped to character glyph path
            cb.beginText();
            cb.setFontAndSize(bf, 1);
            cb.setTextMatrix(270f, 0f, 0f, 270f, 60f, 120f);
            cb.setPatternFill(p2);
            cb.showText("ABC");
            cb.endText();
           
            // draw a circle
            cb.setPatternFill(p2);
            cb.setGrayStroke(0.0f);
            cb.circle(150f, 400f, 150f);
            cb.fillStroke();
           
            cb.sanityCheck();
        }
        catch(Exception e) {
            e.printStackTrace();
        }
       
        // finally, we close the document
        document.close();
    }
View Full Code Here

   */
  public static void main(String[] args) {

    System.out.println("padding - leading");
    // step1
    LwgDocument document = new LwgDocument(LwgPageSize.A4.rotate(), 10, 10, 10, 10);
    try {
      // step2
      PdfWriter.getInstance(document,
          new GfrFileOutputStream("com.lowagie.examples.objects.tables.CellPaddingLeading.pdf"));
      // step3
      document.open();
      // step4
      LwgPdfPTable table = new LwgPdfPTable(2);
      LwgPdfPCell cell;
      Paragraph p = new Paragraph("Quick brown fox jumps over the lazy dog. Quick brown fox jumps over the lazy dog.");
      table.add("default");
      table.add(p);
      table.add("padding 10");
      cell = new LwgPdfPCell(p);
      cell.setPadding(10f);
      table.add(cell);
      table.add("no padding at all");
      cell = new LwgPdfPCell(p);
      cell.setPadding(0f);
      table.add(cell);
      table.add("no padding at the top; large padding at the left");
      cell = new LwgPdfPCell(p);
      cell.setPaddingTop(0f);
      cell.setPaddingLeft(20f);
      table.add(cell);
      document.add(table);
     
      document.newPage();
      table = new LwgPdfPTable(2);
      table.add("no leading at all");
      table.getDefaultCell().setLeading(0f, 0f);
      table.add("blah blah\nblah blah blah\nblah blah\nblah blah blah\nblah blah\nblah blah blah\nblah blah\nblah blah blah\n");
      table.getDefaultCell().setLeading(14f, 0f);
      table.add("fixed leading of 14pt");
      table.add("blah blah\nblah blah blah\nblah blah\nblah blah blah\nblah blah\nblah blah blah\nblah blah\nblah blah blah\n");
      table.add("relative leading of 1.0 times the fontsize");
      table.getDefaultCell().setLeading(0f, 1.0f);
      table.add("blah blah\nblah blah blah\nblah blah\nblah blah blah\nblah blah\nblah blah blah\nblah blah\nblah blah blah\n");
      document.add(table);
    } catch (Exception de) {
      de.printStackTrace();
    }
    // step5
    document.close();
  }
View Full Code Here

   */
  public static void main(String[] args) {

    System.out.println("Nested Tables");
    // step1
    LwgDocument document = new LwgDocument(LwgPageSize.A4.rotate(), 10, 10, 10, 10);
    try {
      // step2
      PdfWriter.getInstance(document,
          new GfrFileOutputStream("com.lowagie.examples.objects.tables.NestedTables.pdf"));
      // step3
      document.open();
      // step4
            LwgPdfPTable table = new LwgPdfPTable(4);
            LwgPdfPTable nested1 = new LwgPdfPTable(2);
            nested1.add("1.1");
            nested1.add("1.2");
            LwgPdfPTable nested2 = new LwgPdfPTable(1);
            nested2.add("2.1");
            nested2.add("2.2");
            for (int k = 0; k < 24; ++k) {
                if (k == 1) {
                    table.add(nested1);
                }
                else if (k == 20) {
                    table.add(nested2);
                }
                else {
                    table.add("cell " + k);
                }
            }
            document.add(table);
            // step 5: we close the document
            document.close();
    } catch (Exception de) {
      de.printStackTrace();
    }
    // step5
    document.close();
  }
View Full Code Here

   */
  public static void main(String[] args) {

    System.out.println("Split rows");
    // step1
    LwgDocument document1 = new LwgDocument(LwgPageSize.A4.rotate(), 10, 10, 10, 10);
    LwgDocument document2 = new LwgDocument(LwgPageSize.A4.rotate(), 10, 10, 10, 10);
    LwgDocument document3 = new LwgDocument(LwgPageSize.A4.rotate(), 10, 10, 10, 10);
    try {
      // step2
      PdfWriter.getInstance(document1,
          new GfrFileOutputStream("com.lowagie.examples.objects.tables.SplitRows_Between.pdf"));
      PdfWriter.getInstance(document2,
          new GfrFileOutputStream("com.lowagie.examples.objects.tables.SplitRows_Within.pdf"));
      PdfWriter.getInstance(document3,
          new GfrFileOutputStream("com.lowagie.examples.objects.tables.SplitRows_OmitRows.pdf"));
      // step3
      document1.open();
      document2.open();
      document3.open();
      // step4
      String text = "Quick brown fox jumps over the lazy dog. ";
      for (int i = 0; i < 5; i++) text += text;
      LwgPdfPTable table = new LwgPdfPTable(2);
      LwgPdfPCell largeCell;
      LwgPhrase phrase;
      for (int i = 0; i < 10; i++) {
        phrase = new LwgPhrase(text);
        for (int j = 0; j < i; j++) {
          phrase.add(new LwgPhrase(text));
        }
        if (i == 7) phrase = new LwgPhrase(text);
        table.add(String.valueOf(i));
        largeCell = new LwgPdfPCell(phrase);
        table.add(largeCell);
      }
      document1.add(table);
      table.setSplitLate(false);
      document2.add(table);
      table.setSplitRows(false);
      document3.add(table);
    } catch (Exception de) {
      de.printStackTrace();
    }
    // step5
    document1.close();
    document2.close();
    document3.close();
  }
View Full Code Here

   */
  public static void main(String[] args) {

    System.out.println("Width");
    // step1
    LwgDocument document = new LwgDocument(LwgPageSize.A4, 36, 36, 36, 36);
    try {
      // step2
      PdfWriter.getInstance(document,
          new GfrFileOutputStream("com.lowagie.examples.objects.tables.CellWidths.pdf"));
      // step3
      document.open();
      // step4
      float[] widths = {0.1f, 0.1f, 0.05f, 0.75f};
      LwgPdfPTable table = new LwgPdfPTable(widths);
      table.add("10%");
      table.add("10%");
      table.add("5%");
      table.add("75%");
      table.add("aa");
      table.add("aa");
      table.add("a");
      table.add("aaaaaaaaaaaaaaa");
      table.add("bb");
      table.add("bb");
      table.add("b");
      table.add("bbbbbbbbbbbbbbb");
      table.add("cc");
      table.add("cc");
      table.add("c");
      table.add("ccccccccccccccc");
      document.add(table);
      document.add(new Paragraph("We change the percentages:\n\n"));
      widths[0] = 20f;
      widths[1] = 20f;
      widths[2] = 10f;
      widths[3] = 50f;
      table.setWidths(widths);
      document.add(table);
      widths[0] = 40f;
      widths[1] = 40f;
      widths[2] = 20f;
      widths[3] = 300f;
      LwgRectangle r = new LwgRectangle(LwgPageSize.A4.getRight(72), LwgPageSize.A4.getTop(72));
      table.setWidthPercentage(widths, r);
      document.add(new Paragraph("We change the percentage using absolute widths:\n\n"));
      document.add(table);
      document.add(new Paragraph("We use a locked width:\n\n"));
      table.setTotalWidth(300);
      table.setLockedWidth(true);
      document.add(table);
    } catch (Exception de) {
      de.printStackTrace();
    }
    // step5
    document.close();
  }
View Full Code Here

    public static void main(String[] args) {
       
        System.out.println("True Types (embedded)");
       
        // step 1: creation of a document-object
        LwgDocument document = new LwgDocument();
       
        try {
           
            // step 2: creation of the writer-object
            PdfWriter.getInstance(document, new GfrFileOutputStream("com.lowagie.examples.fonts.UnicodeExample.pdf"));
           
            // step 3: we open the document
            document.open();
           
            // step 4: we add content to the document
            BaseFont bfComic = BaseFont.createFont("c:\\windows\\fonts\\comic.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
            LwgFont font = new LwgFont(bfComic, 12);
            String text1 = "This is the quite popular True Type font 'Comic'.";
            String text2 = "Some greek characters: \u0393\u0394\u03b6";
            String text3 = "Some cyrillic characters: \u0418\u044f";
            document.add(new Paragraph(text1, font));
            document.add(new Paragraph(text2, font));
            document.add(new Paragraph(text3, 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("Negative Leading");

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

      // step 3: we open the document
      document.open();
      // step 4:
      document.add(new LwgPhrase(16, "\n\n\n"));
      document
          .add(new LwgPhrase(
              -16,
              "Hello, this is a very long phrase to show you the somewhat odd effect of a negative leading. You can write from bottom to top. This is not fully supported. It's something between a feature and a bug."));
    } 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.