Package com.lowagie.text

Examples of com.lowagie.text.LwgDocument


     *
     * @param args no arguments needed
     */
    public static void main(String[] args) {
        System.out.println("Table of contents and Cell borders");
        LwgDocument document = new LwgDocument();
        try {
            RtfWriter2 writer2 = RtfWriter2.getInstance(document, new FileOutputStream("toc.rtf"));
           
            writer2.setAutogenerateTOCEntries(true);
           
            document.open();
           
            Paragraph para = new Paragraph();
            para.add(new RtfTableOfContents("RIGHT CLICK AND HERE AND SELECT \"UPDATE FIELD\" TO UPDATE."));
            document.add(para);

            Paragraph par = new Paragraph("This is some sample content.");
            Chapter chap1 = new Chapter("Chapter 1", 1);
            chap1.add(par);
            Chapter chap2 = new Chapter("Chapter 2", 2);
            chap2.add(par);
            document.add(chap1);
            document.add(chap2);
           
            for(int i = 0; i < 300; i++) {
                if(i == 158) {
                    document.add(new RtfTOCEntry("This is line 158."));
                }
                document.add(new Paragraph("Line " + i));
            }
           
            document.add(new RtfTOCEntry("Cell border demonstration"));

            Table table = new Table(3);

            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);
           
            document.add(table);
        }
        catch(DocumentException de) {
            System.err.println(de.getMessage());
        }
        catch(IOException ioe) {
            System.err.println(ioe.getMessage());
        }
        document.close();
    }
View Full Code Here


    public static void main(String[] args) {
       
        System.out.println("Images in HTML");
       
        // 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_wrong.html"));
            HtmlWriter writer = HtmlWriter.getInstance(document, new FileOutputStream("images_right.html"));
            writer.setImagepath("./");
           
            // 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("otsoe.jpg");
            document.add(jpg);
            document.add(new Paragraph("getacro.gif"));
            LwgImage gif= LwgImage.getInstance("getacro.gif");
            document.add(gif);
            document.add(new Paragraph("pngnow.png"));
            LwgImage png = LwgImage.getInstance("pngnow.png");
            document.add(png);
            document.add(new Paragraph("iText.bmp"));
            LwgImage bmp = LwgImage.getInstance("iText.bmp");
            document.add(bmp);
            document.add(new Paragraph("iText.wmf"));
            LwgImage wmf = LwgImage.getInstance("iText.wmf");
            document.add(wmf);
            document.add(new Paragraph("iText.tif"));
            LwgImage tiff = LwgImage.getInstance("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("Some Fancy Lists");

    // step 1: creation of a document-object
    LwgDocument document = new LwgDocument();
    try {
            // step 2:
            PdfWriter.getInstance(document, new FileOutputStream("fancylists.pdf"));
           
            // step 3: we open the document
            document.open();
           
            // step 4:

      // RomanList
      RomanList roman = new RomanList(35);
      roman.setLowercase(true);
      roman.add(new ListItem("first item"));
      roman.add(new ListItem("second item blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah"));
      for (int i = 3; i < 151; i++) {
        roman.add(i + "th item");
      }
      document.add(roman);
      document.newPage();
      RomanList roman2 = new RomanList(35);
      roman2.add(new ListItem("first item"));
      roman2.add(new ListItem("second item"));
      for (int i = 3; i < 11; i++) {
        roman2.add(i + "th item");
      }
      document.add(roman2);
      document.newPage();
     
      // GreekList
      GreekList greek = new GreekList(15);
      greek.setLowercase(true);
      greek.add(new ListItem("first item"));
      greek.add(new ListItem("second item"));
      for (int i = 3; i < 20; i++) {
        greek.add(i + "th item");
      }
      document.add(greek);
      document.newPage();
     
      // GreekList
      GreekList greek2 = new GreekList(15);
      greek2.setLowercase(false);
      greek2.add(new ListItem("first item"));
      greek2.add(new ListItem("second item"));
      for (int i = 3; i < 20; i++) {
        greek2.add(i + "th item");
      }
      document.add(greek2);
     
      // ZapfDingbatsList
      ZapfDingbatsList z = new ZapfDingbatsList(42,15);
      z.add(new ListItem("first item"));
      z.add(new ListItem("second item"));
      for (int i = 3; i < 20; i++) {
        z.add(i + "th item");
      }
      document.add(z);
      document.newPage();
     
      // ZapfDingbatsNumberList
      ZapfDingbatsNumberList z0 = new ZapfDingbatsNumberList(0, 15);
      z0.add(new ListItem("first item"));
      z0.add(new ListItem("second item"));
      for (int i = 3; i < 11; i++) {
        z0.add(i + "th item");
      }
      document.add(z0);
      ZapfDingbatsNumberList z1 = new ZapfDingbatsNumberList(1, 15);
      z1.add(new ListItem("first item"));
      z1.add(new ListItem("second item"));
      for (int i = 3; i < 11; i++) {
        z1.add(i + "th item");
      }
      document.add(z1);
      ZapfDingbatsNumberList z2 = new ZapfDingbatsNumberList(2, 15);
      z2.add(new ListItem("first item"));
      z2.add(new ListItem("second item"));
      for (int i = 3; i < 11; i++) {
        z2.add(i + "th item");
      }
      document.add(z2);
      ZapfDingbatsNumberList z3 = new ZapfDingbatsNumberList(3, 15);
      z3.add(new ListItem("first item"));
      z3.add(new ListItem("second item"));
      for (int i = 3; i < 11; i++) {
        z3.add(i + "th item");
      }
      document.add(z3);

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

    // 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 HTML-stream to a file
      HtmlWriter.getInstance(document,
          new FileOutputStream("HelloWorld.html"));

      // step 3: we open the document
      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("TableSpacing");
    // step1
    LwgDocument document = new LwgDocument(LwgPageSize.A4);
    try {
      // step2
      PdfWriter.getInstance(document,
          new GfrFileOutputStream("com.lowagie.examples.objects.tables.TableSpacing.pdf"));
      // step3
      document.open();
      // step4
      LwgPdfPTable table = new LwgPdfPTable(3);
      LwgPdfPCell cell = new LwgPdfPCell(new Paragraph("header with colspan 3"));
      cell.setColspan(3);
      table.add(cell);
      table.add("1.1");
      table.add("2.1");
      table.add("3.1");
      table.add("1.2");
      table.add("2.2");
      table.add("3.2");
      cell = new LwgPdfPCell(new Paragraph("cell test1"));
      cell.setBorderColor(new Color(255, 0, 0));
      table.add(cell);
      cell = new LwgPdfPCell(new Paragraph("cell test2"));
      cell.setColspan(2);
      cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
      table.add(cell);
      table.setWidthPercentage(50);
      document.add(new Paragraph("We add 2 tables:"));
      document.add(table);
      document.add(table);
      document.add(new Paragraph("They are glued to eachother"));
      document.add(table);
      document.add(new Paragraph("This is not very nice. Turn to the next page to see how we solved this"));
      document.newPage();
      document.add(new Paragraph("We add 2 tables, but with a certain 'SpacingBefore':"));
      table.setSpacingBefore(15f);
      document.add(table);
      document.add(table);
      document.add(new Paragraph("Unfortunately, there was no spacing after."));
      table.setSpacingAfter(15f);
      document.add(table);
      document.add(new Paragraph("This is much better, don't you think so?"));
    } catch (Exception de) {
      de.printStackTrace();
    }
    // step5
    document.close();
  }
View Full Code Here

     * Shading example.
     * @param args no arguments needed
     */
    public static void main(String[] args) {
        System.out.println("Shading pattern");
        LwgDocument document = new LwgDocument(LwgPageSize.A4, 50, 50, 50, 50);
        try {
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("shading_pattern.pdf"));
            document.open();

            PdfShading shading = PdfShading.simpleAxial(writer, 100, 100, 400, 100, Color.red, Color.cyan);
            PdfShadingPattern shadingPattern = new PdfShadingPattern(shading);
            PdfContentByte cb = writer.getDirectContent();
            BaseFont bf = BaseFont.createFont(BaseFont.TIMES_BOLD, BaseFont.WINANSI, false);
            cb.setShadingFill(shadingPattern);
            cb.beginText();
            cb.setTextMatrix(100, 100);
            cb.setFontAndSize(bf, 40);
            cb.showText("Look at this text!");
            cb.endText();
            PdfShading shadingR = PdfShading.simpleRadial(writer, 200, 500, 50, 300, 500, 100, new Color(255, 247, 148), new Color(247, 138, 107), false, false);
            cb.paintShading(shadingR);
            cb.sanityCheck();
            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("adding cells at a specific position");
        // 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.objects.tables.alternatives.SpecificCells.pdf"));
            // step 3: we open the document
            document.open();
            // step 4: we create a table and add it to the document
            Table aTable;
           
            aTable = new Table(4,4);    // 4 rows, 4 columns
            aTable.setAlignment(LwgElement.ALIGN_RIGHT);
            aTable.addCell("2.2", new Point(2,2));
            aTable.addCell("3.3", new Point(3,3));
            aTable.addCell("2.1", new Point(2,1));
            aTable.addCell("1.3", new Point(1,3));
            document.add(aTable);
      document.add(new Paragraph("converted to PdfPTable:"));
      aTable.setConvert2pdfptable(true);
      document.add(aTable);
            document.newPage();    
            aTable = new Table(4,4);    // 4 rows, 4 columns
            aTable.setAlignment(LwgElement.ALIGN_CENTER);
            aTable.addCell("2.2", new Point(2,2));
            aTable.addCell("3.3", new Point(3,3));
            aTable.addCell("2.1", new Point(2,1));
            aTable.addCell("1.3", new Point(1,3));
            aTable.addCell("5.2", new Point(5,2));
            aTable.addCell("6.1", new Point(6,1));
            aTable.addCell("5.0", new Point(5,0))
            document.add(aTable);
      document.add(new Paragraph("converted to PdfPTable:"));
      aTable.setConvert2pdfptable(true);
      document.add(aTable);
            document.newPage();
            aTable = new Table(2,2);    // 2 rows, 2 columns
            aTable.setAlignment(LwgElement.ALIGN_LEFT);
            aTable.setAutoFillEmptyCells(true);
            aTable.addCell("0.0");
            aTable.addCell("0.1");
            aTable.addCell("1.0");
            aTable.addCell("1.1");
            aTable.addColumns(2);
            float[] f = {1f, 1f, 1f, 1f};
            aTable.setWidths(f);
            aTable.addCell("2.2", new Point(2,2));
            aTable.addCell("3.3", new Point(3,3));
            aTable.addCell("2.1", new Point(2,1));
            aTable.addCell("1.3", new Point(1,3));
            aTable.addCell("5.2", new Point(5,2));
            aTable.addCell("6.1", new Point(6,1));
            aTable.addCell("5.0", new Point(5,0));
            document.add(aTable);
      document.add(new Paragraph("converted to PdfPTable:"));
      aTable.setConvert2pdfptable(true);
      document.add(aTable);
        }
        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

     * Shading example.
     * @param args no arguments needed
     */
    public static void main(String[] args) {
        System.out.println("Shading");
        LwgDocument document = new LwgDocument(LwgPageSize.A4, 50, 50, 50, 50);
        try {
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("shading.pdf"));
            document.open();

            PdfFunction function1 = PdfFunction.type2(writer, new float[]{0, 1}, null,
                new float[]{.929f, .357f, 1, .298f}, new float[]{.631f, .278f, 1, .027f}, 1.048f);
            PdfFunction function2 = PdfFunction.type2(writer, new float[]{0, 1}, null,
                new float[]{.929f, .357f, 1, .298f}, new float[]{.941f, .4f, 1, .102f}, 1.374f);
            PdfFunction function3 = PdfFunction.type3(writer, new float[]{0, 1}, null,
                new PdfFunction[]{function1, function2}, new float[]{.708f}, new float[]{1, 0, 0, 1});
            PdfShading shading = PdfShading.type3(writer, new CMYKColor(0, 0, 0, 0),
                new float[]{0, 0, .096f, 0, 0, 1}, null, function3, new boolean[]{true, true});
            PdfContentByte cb = writer.getDirectContent();
            cb.moveTo(316.789f, 140.311f);
            cb.curveTo(303.222f, 146.388f, 282.966f, 136.518f, 279.122f, 121.983f);
            cb.lineTo(277.322f, 120.182f);
            cb.curveTo(285.125f, 122.688f, 291.441f, 121.716f, 298.156f, 119.386f);
            cb.lineTo(336.448f, 119.386f);
            cb.curveTo(331.072f, 128.643f, 323.346f, 137.376f, 316.789f, 140.311f);
            cb.clip();
            cb.newPath();
            cb.saveState();
            cb.concatCTM(27.7843f, 0, 0, -27.7843f, 310.2461f, 121.1521f);
            cb.paintShading(shading);
            cb.restoreState();
           
            cb.sanityCheck();
           
            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");
        // 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("transparency.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);
           
            pictureCircles(gap, 500, cb);
            cb.saveState();
            PdfGState gs1 = new PdfGState();
            gs1.setFillOpacity(0.5f);
            cb.setGState(gs1);
            pictureCircles(200 + 2 * gap, 500, cb);
            cb.restoreState();

            PdfTemplate tp = cb.createTemplate(200, 200);
            cb.saveState();
            pictureCircles(0, 0, tp);
            PdfTransparencyGroup group = new PdfTransparencyGroup();
            tp.setGroup(group);
            tp.sanityCheck();
            cb.setGState(gs1);
            cb.addTemplate(tp, gap, 500 - 200 - gap);
            cb.restoreState();

            tp = cb.createTemplate(200, 200);
            cb.saveState();
            PdfGState gs2 = new PdfGState();
            gs2.setFillOpacity(0.5f);
            gs2.setBlendMode(PdfGState.BM_SOFTLIGHT);
            tp.setGState(gs2);
            tp.sanityCheck();
            pictureCircles(0, 0, tp);
            tp.setGroup(group);
            cb.addTemplate(tp, 200 + 2 * gap, 500 - 200 - gap);
            cb.restoreState();

            cb.resetRGBColorFill();
            ColumnText ct = new ColumnText(cb);
            LwgPhrase ph = new LwgPhrase("Ungrouped objects\nObject opacity = 1.0");
            ct.setSimpleColumn(ph, gap, 0, gap + 200, 500, 18, LwgElement.ALIGN_CENTER);
            ct.go();
           
            ph = new LwgPhrase("Ungrouped objects\nObject opacity = 0.5");
            ct.setSimpleColumn(ph, 200 + 2 * gap, 0, 200 + 2 * gap + 200, 500, 18, LwgElement.ALIGN_CENTER);
            ct.go();
           
            ph = new LwgPhrase("Transparency group\nObject opacity = 1.0\nGroup opacity = 0.5\nBlend mode = Normal");
            ct.setSimpleColumn(ph, gap, 0, gap + 200, 500 - 200 - gap, 18, LwgElement.ALIGN_CENTER);
            ct.go();
           
            ph = new LwgPhrase("Transparency group\nObject opacity = 0.5\nGroup opacity = 1.0\nBlend mode = SoftLight");
            ct.setSimpleColumn(ph, 200 + 2 * gap, 0, 200 + 2 * gap + 200, 500 - 200 - gap, 18, LwgElement.ALIGN_CENTER);
            ct.go();
           
            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("table width and alignment");
    // step1
    LwgDocument document = new LwgDocument(LwgPageSize.A4);
    try {
      // step2
      PdfWriter.getInstance(document,
          new GfrFileOutputStream("com.lowagie.examples.objects.tables.TableWidthAlignment.pdf"));
      // step3
      document.open();
      // step4
      LwgPdfPTable table = new LwgPdfPTable(3);
      LwgPdfPCell cell = new LwgPdfPCell(new Paragraph("header with colspan 3"));
      cell.setColspan(3);
      table.add(cell);
      table.add("1.1");
      table.add("2.1");
      table.add("3.1");
      table.add("1.2");
      table.add("2.2");
      table.add("3.2");
      cell = new LwgPdfPCell(new Paragraph("cell test1"));
      cell.setBorderColor(new Color(255, 0, 0));
      table.add(cell);
      cell = new LwgPdfPCell(new Paragraph("cell test2"));
      cell.setColspan(2);
      cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
      table.add(cell);
      document.add(table);
      table.setWidthPercentage(100);
      document.add(table);
      table.setWidthPercentage(50);
      table.setHorizontalAlignment(LwgElement.ALIGN_RIGHT);
      document.add(table);
      table.setHorizontalAlignment(LwgElement.ALIGN_LEFT);
      document.add(table);
    } catch (Exception de) {
      de.printStackTrace();
    }
    // step5
    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.