Package com.lowagie.text

Examples of com.lowagie.text.LwgDocument


     * @param args no arguments needed.
     */
    public static void main(String[] args) {
        System.out.println("Old Table class");
        // 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.objects.tables.alternatives.PaddingBorders.pdf"));
            // step 3: we open the document
            document.open();
            // step 4: we create a table and add it to the document
            Table table = new Table(3);
            table.setBorderWidth(1);
            table.setBorderColor(new Color(0, 0, 255));
            table.setPadding(10);
            LwgCell cell = new LwgCell("header");
            cell.setHeader(true);
            cell.setColspan(3);
            table.addCell(cell);
            table.addCell("1.1");
            table.addCell("2.1");
            table.addCell("3.1");
            table.addCell("1.2");
            table.addCell("2.2");
            table.addCell("3.2");
            document.add(table);
            table.setConvert2pdfptable(true);
      document.add(new Paragraph("converted to PdfPTable:"));
            document.add(table);
           
            table = new Table(3);
            table.setBorderWidth(3);
            table.setBorderColor(new Color(255, 0, 0));
            table.setPadding(0);
            cell = new LwgCell("header");
            cell.setHeader(true);
            cell.setBorderColorBottom(new Color(0, 0, 255));
            cell.setColspan(3);
            table.addCell(cell);
            table.addCell("1.1");
            cell = new LwgCell("2.1");
            cell.setBorderWidthLeft(4);
            cell.setBorderWidthRight(8);
            cell.setBorderWidthTop(2);
            cell.setBorderWidthBottom(10);
            cell.setUseBorderPadding(true);
            cell.setBorderColorBottom(new Color(0, 255, 0));
            table.addCell(cell);
            table.addCell("3.1");
            table.addCell("1.2");
            table.addCell("2.2");
            table.addCell("3.2");
            document.add(table);
            table.setConvert2pdfptable(true);
      document.add(new Paragraph("converted to PdfPTable:"));
            document.add(table);
        }
        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("large cell");
      // step 1: creation of a document-object
      LwgDocument document = new LwgDocument(LwgPageSize.A6);
      try
      {
         // step 2: creation of the writer-object
         PdfWriter.getInstance(document,
                 new GfrFileOutputStream("com.lowagie.examples.objects.tables.alternatives.LargeCell.pdf"));
         // step 3: we open the document
         document.open();
         // step 4: we create a table and add it to the document
         Table table = new Table(3);
         table.setCellsFitPage(true);
         String text = "long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long text";
         table.addCell("text");
         table.addCell("text");
         table.addCell("text");
         table.addCell(text);
         table.addCell(text + text);
         table.addCell(text);
         table.addCell("text");
         table.addCell("text");
         table.addCell("text");
         document.add(table);
      }
      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("document.add(BigTable)");
    // step1
    LwgDocument document = new LwgDocument(LwgPageSize.A4.rotate(), 10, 10, 10, 10);
    try {
      // step2
      PdfWriter.getInstance(document,
          new GfrFileOutputStream("com.lowagie.examples.objects.tables.AddBigTable.pdf"));
      // step3
      document.open();
      // step4
      String[] bogusData = { "M0065920", "SL", "FR86000P", "PCGOLD",
          "119000", "96 06", "2001-08-13", "4350", "6011648299",
          "FLFLMTGP", "153", "119000.00" };
      int NumColumns = 12;

      LwgPdfPTable datatable = new LwgPdfPTable(NumColumns);
      int headerwidths[] = { 9, 4, 8, 10, 8, 11, 9, 7, 9, 10, 4, 10 }; // percentage
      datatable.setWidths(headerwidths);
      datatable.setWidthPercentage(100); // percentage
      datatable.getDefaultCell().setPadding(3);
      datatable.getDefaultCell().setBorderWidth(2);
      datatable.getDefaultCell().setHorizontalAlignment(
          LwgElement.ALIGN_CENTER);
      datatable.add("Clock #");
      datatable.add("Trans Type");
      datatable.add("Cusip");
      datatable.add("Long Name");
      datatable.add("Quantity");
      datatable.add("Fraction Price");
      datatable.add("Settle Date");
      datatable.add("Portfolio");
      datatable.add("ADP Number");
      datatable.add("Account ID");
      datatable.add("Reg Rep ID");
      datatable.add("Amt To Go ");

      datatable.setHeaderRows(1); // this is the end of the table header

      datatable.getDefaultCell().setBorderWidth(1);
      for (int i = 1; i < 750; i++) {
        if (i % 2 == 1) {
          datatable.getDefaultCell().setGrayFill(0.9f);
        }
        for (int x = 0; x < NumColumns; x++) {
          datatable.add(bogusData[x]);
        }
        if (i % 2 == 1) {
          datatable.getDefaultCell().setGrayFill(1);
        }
      }
      document.add(datatable);
    } catch (Exception de) {
      de.printStackTrace();
    }
    // step5
    document.close();
  }
View Full Code Here

    */
   public static void main(String[] args)
   {
      System.out.println("Nested tables");
      // 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.NestedTables.pdf"));
         // step 3: we open the document
         document.open();
         // step 4: we create a table and add it to the document

         // example 1

         Table secondTable = new Table(2);
         secondTable.addCell("2nd table 0.0");
         secondTable.addCell("2nd table 0.1");
         secondTable.addCell("2nd table 1.0");
         secondTable.addCell("2nd table 1.1");

         Table aTable = new Table(4, 4);    // 4 rows, 4 columns
         aTable.setAutoFillEmptyCells(true);
         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.insertTable(secondTable, new Point(1, 3));
         document.add(aTable);
         document.add(new Paragraph("converted to PdfPTable:"));
         aTable.setConvert2pdfptable(true);
         document.add(aTable);
         document.newPage();

         // example 2

         Table thirdTable = new Table(2);
         thirdTable.addCell("3rd table 0.0");
         thirdTable.addCell("3rd table 0.1");
         thirdTable.addCell("3rd table 1.0");
         thirdTable.addCell("3rd table 1.1");

         aTable = new Table(5, 5);
         aTable.setAutoFillEmptyCells(true);
         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.insertTable(secondTable, new Point(1, 3));
         aTable.insertTable(thirdTable, new Point(6, 2));
         document.add(aTable);
         document.add(new Paragraph("converted to PdfPTable:"));
         aTable.setConvert2pdfptable(true);
         document.add(aTable);
         document.newPage();

         // example 3
         aTable = new Table(3);
         float[] widths =
         {
            1, 2, 1
         };
         aTable.setWidths(widths);
         aTable.addCell("1.1");
         aTable.addCell("1.2");
         aTable.addCell("1.3");
         // nested
         Table t2 = new Table(2);
         t2.addCell("2.1");
         t2.addCell("2.2");

         // now insert the nested
         aTable.insertTable(t2);
         aTable.addCell("new cell");
         document.add(aTable);
         document.add(new Paragraph("converted to PdfPTable:"));
         aTable.setConvert2pdfptable(true);
         document.add(aTable);
         document.newPage();

         // relative column widths are preserved

         Table a = new Table(2);
         a.setWidths(new float[]
                 {
                    85, 15
                 });
         a.addCell("a-1");
         a.addCell("a-2");

         Table b = new Table(5);
         b.setWidths(new float[]
                 {
                    15, 7, 7, 7, 7
                 });
         b.addCell("b-1");
         b.addCell("b-2");
         b.addCell("b-3");
         b.addCell("b-4");
         b.addCell("b-5");

         // now, insert these 2 tables into a third for layout purposes
         Table c = new Table(3, 1);
         c.setWidth(100.0f);
         c.setWidths(new float[]
                 {
                    20, 2, 78
                 });
         c.insertTable(a, new Point(0, 0));
         c.insertTable(b, new Point(0, 2));

         document.add(c);
         document.add(new Paragraph("converted to PdfPTable:"));
         c.setConvert2pdfptable(true);
         document.add(c);

      }
      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("Image in a Cell");

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

    try {
      // step 2:
      PdfWriter.getInstance(document, new GfrFileOutputStream("com.lowagie.examples.objects.tables.ImageCell.pdf"));

      // step 3: we open the document
      document.open();
      LwgImage image = LwgImage.getInstance("otsoe.jpg");
      float[] widths = {1f, 4f};
      LwgPdfPTable table = new LwgPdfPTable(widths);
      table.add("This is my dog");
      table.add(image);
      table.add("This two");
      table.add(new LwgPdfPCell(image, true));
      table.add("This three");
      table.add(new LwgPdfPCell(image, false));
      document.add(table);
    } 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("Rectangle methods on PdfPCell");
    // step1
    LwgDocument document = new LwgDocument(LwgPageSize.A4);
    try {
      // step2
      PdfWriter.getInstance(document,
          new GfrFileOutputStream("com.lowagie.examples.objects.tables.CellColors.pdf"));
      // step3
      document.open();
      // step4
      LwgPdfPTable table = new LwgPdfPTable(4);
      LwgPdfPCell cell;
      cell = new LwgPdfPCell(new Paragraph("test colors:"));
      table.add(cell);
      cell = new LwgPdfPCell(new Paragraph("red"));
      cell.setBorder(LwgRectangle.NO_BORDER);
      cell.setBackgroundColor(Color.red);
      table.add(cell);
      cell = new LwgPdfPCell(new Paragraph("green"));
      cell.setBorder(LwgRectangle.BOTTOM);
      cell.setBorderColorBottom(Color.magenta);
      cell.setBorderWidthBottom(10f);
      cell.setBackgroundColor(Color.green);
      table.add(cell);
      cell = new LwgPdfPCell(new Paragraph("blue"));
      cell.setBorder(LwgRectangle.TOP);
          cell.setUseBorderPadding(true);
      cell.setBorderWidthTop(5f);
      cell.setBorderColorTop(Color.cyan);
      cell.setBackgroundColor(Color.blue);
      table.add(cell);
      cell = new LwgPdfPCell(new Paragraph("test GrayFill:"));
      table.add(cell);
      cell = new LwgPdfPCell(new Paragraph("0.25"));
      cell.setBorder(LwgRectangle.NO_BORDER);
      cell.setGrayFill(0.25f);
      table.add(cell);
      cell = new LwgPdfPCell(new Paragraph("0.5"));
      cell.setBorder(LwgRectangle.NO_BORDER);
      cell.setGrayFill(0.5f);
      table.add(cell);
      cell = new LwgPdfPCell(new Paragraph("0.75"));
      cell.setBorder(LwgRectangle.NO_BORDER);
      cell.setGrayFill(0.75f);
      table.add(cell);
      document.add(table);
    } catch (Exception de) {
      de.printStackTrace();
    }
    // step5
    document.close();
  }
View Full Code Here

  public static void main(String[] args) {

    System.out.println("Font Style Propagation");

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

      // step 3: we open the document
      document.open();
      // step 4:
      LwgPhrase myPhrase = new LwgPhrase("Hello 1! ", new LwgFont(LwgFont.TIMES_ROMAN, 8, LwgFont.BOLD));
            myPhrase.add(new LwgPhrase("some other font ", new LwgFont(LwgFont.HELVETICA, 8)));
            myPhrase.add(new LwgPhrase("This is the end of the sentence.\n", new LwgFont(LwgFont.TIMES_ROMAN, 8, LwgFont.ITALIC)));
            document.add(myPhrase);
           
            myPhrase = new LwgPhrase(12);
            myPhrase.add(new LwgPhrase("Hello 2! ", new LwgFont(LwgFont.TIMES_ROMAN, 8, LwgFont.BOLD)));
            myPhrase.add(new LwgPhrase("This is the end of the sentence.\n", new LwgFont(LwgFont.TIMES_ROMAN, 8, LwgFont.ITALIC)));
            document.add(myPhrase);
           
            myPhrase = new LwgPhrase("Hello 3! ", FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, LwgFont.BOLD));
            myPhrase.add(new LwgPhrase("some other font ", FontFactory.getFont(FontFactory.HELVETICA, 8)));
            myPhrase.add(new LwgPhrase("This is the end of the sentence.\n", FontFactory.getFont(FontFactory.TIMES_ROMAN, 8, LwgFont.ITALIC)));
            document.add(myPhrase);
           
            Paragraph myParagraph = new Paragraph("Hello 1bis! ", new LwgFont(LwgFont.TIMES_ROMAN, 8, LwgFont.BOLD));
            myParagraph.add(new Paragraph("This is the end of the sentence.", new LwgFont(LwgFont.TIMES_ROMAN, 8, LwgFont.ITALIC)));
            document.add(myParagraph);
           
            myParagraph = new Paragraph(12);
            myParagraph.add(new Paragraph("Hello 3bis! ", new LwgFont(LwgFont.TIMES_ROMAN, 8, LwgFont.BOLD)));
            myParagraph.add(new Paragraph("This is the end of the sentence.", new LwgFont(LwgFont.TIMES_ROMAN, 8, LwgFont.ITALIC)));
            document.add(myParagraph);
    } 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("Table Borders");
    // step1
    LwgDocument document = new LwgDocument(LwgPageSize.A4, 50, 50, 50, 50);
    try {
      // step2
      PdfWriter writer = PdfWriter.getInstance(document,
          new GfrFileOutputStream("com.lowagie.examples.objects.tables.TableBorders.pdf"));
      // step3
      document.open();
      // step4
     
      // page 1
          LwgFont tableFont = FontFactory.getFont("Helvetica", 8, LwgFont.BOLD, Color.BLACK);
          float padding = 0f;
          LwgRectangle border = new LwgRectangle(0f, 0f);
          border.setBorderWidthLeft(6f);
          border.setBorderWidthBottom(5f);
          border.setBorderWidthRight(4f);
          border.setBorderWidthTop(2f);
          border.setBorderColorLeft(Color.RED);
          border.setBorderColorBottom(Color.ORANGE);
          border.setBorderColorRight(Color.YELLOW);
          border.setBorderColorTop(Color.GREEN);
          makeTestPage(tableFont, border, writer, document, padding, true, true);
          LwgFont font = FontFactory.getFont("Helvetica", 10);
          Paragraph p;
          p = new Paragraph("\nVarious border widths and colors\nuseAscender=true, useDescender=true", font);
          document.add(p);
         
          document.newPage();
         
          // page 2
          padding = 2f;
          border = new LwgRectangle(0f, 0f);
          border.setBorderWidthLeft(1f);
          border.setBorderWidthBottom(2f);
          border.setBorderWidthRight(1f);
          border.setBorderWidthTop(2f);
          border.setBorderColor(Color.BLACK);
          makeTestPage(tableFont, border, writer, document, padding, true, true);
          p = new Paragraph("More typical use - padding of 2\nuseBorderPadding=true, useAscender=true, useDescender=true", font);
          document.add(p);
         
          document.newPage();
         
          // page 3
          padding = 0f;
          border = new LwgRectangle(0f, 0f);
          border.setBorderWidthLeft(1f);
          border.setBorderWidthBottom(2f);
          border.setBorderWidthRight(1f);
          border.setBorderWidthTop(2f);
          border.setBorderColor(Color.BLACK);
          makeTestPage(tableFont, border, writer, document, padding, false, true);
          p = new Paragraph("\nuseBorderPadding=true, useAscender=false, useDescender=true", font);
          document.add(p);
         
          document.newPage();
         
          // page 4
          padding = 0f;
          border = new LwgRectangle(0f, 0f);
          border.setBorderWidthLeft(1f);
          border.setBorderWidthBottom(2f);
          border.setBorderWidthRight(1f);
          border.setBorderWidthTop(2f);
          border.setBorderColor(Color.BLACK);
          makeTestPage(tableFont, border, writer, document, padding, false, false);
          p = new Paragraph("\nuseBorderPadding=true, useAscender=false, useDescender=false", font);
          document.add(p);
         
          document.newPage();
         
          // page 5
          padding = 0f;
          border = new LwgRectangle(0f, 0f);
          border.setBorderWidthLeft(1f);
          border.setBorderWidthBottom(2f);
          border.setBorderWidthRight(1f);
          border.setBorderWidthTop(2f);
          border.setBorderColor(Color.BLACK);
          makeTestPage(tableFont, border, writer, document, padding, true, false);
          p = new Paragraph("\nuseBorderPadding=true, useAscender=true, useDescender=false", font);
          document.add(p);
    } catch (Exception de) {
      de.printStackTrace();
    }
    // step5
    document.close();
  }
View Full Code Here

     * @param args no arguments needed
     */
    public static void main(String[] args) {
        System.out.println("table splitting");
        // creation of the document with a certain size and certain margins
        LwgDocument document = new LwgDocument(LwgPageSize.A4.rotate(), 50, 50, 50, 50);
       
        try {
            // creation of the different writers
            PdfWriter.getInstance(document,
                    new GfrFileOutputStream("com.lowagie.examples.objects.tables.alternatives.RepeatingTable.pdf"));
           
            // we add some meta information to the document
            document.addAuthor("Alan Soukup");
            document.addSubject("This is the result of a Test.");
           
            document.open();
           
            Table datatable = new Table(10);
           
            int headerwidths[] = {10, 24, 12, 12, 7, 7, 7, 7, 7, 7};
            datatable.setWidths(headerwidths);
            datatable.setWidth(100);
            datatable.setPadding(3);
           
            // the first cell spans 10 columns
            LwgCell cell = new LwgCell(new LwgPhrase("Administration -System Users Report", FontFactory.getFont(FontFactory.HELVETICA, 24, LwgFont.BOLD)));
            cell.setHorizontalAlignment(LwgElement.ALIGN_CENTER);
            cell.setLeading(30);
            cell.setColspan(10);
            cell.setBorder(LwgRectangle.NO_BORDER);
            cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
            datatable.addCell(cell);
           
            // These cells span 2 rows
            datatable.getDefaultCell().setBorderWidth(2);
            datatable.getDefaultCell().setHorizontalAlignment(1);
            datatable.addCell("User Id");
            datatable.addCell("Name\nAddress");
            datatable.addCell("Company");
            datatable.addCell("Department");
            datatable.addCell("Admin");
            datatable.addCell("Data");
            datatable.addCell("Expl");
            datatable.addCell("Prod");
            datatable.addCell("Proj");
            datatable.addCell("Online");
           
            // this is the end of the table header
            datatable.endHeaders();
           
            datatable.getDefaultCell().setBorderWidth(1);
           
            for (int i = 1; i < 30; i++) {
               
                datatable.getDefaultCell().setHorizontalAlignment(LwgElement.ALIGN_LEFT);
               
                datatable.addCell("myUserId");
                datatable.addCell("Somebody with a very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very, very long long name");
                datatable.addCell("No Name Company");
                datatable.addCell("D" + i);
               
                datatable.getDefaultCell().setHorizontalAlignment(LwgElement.ALIGN_CENTER);
                datatable.addCell("No");
                datatable.addCell("Yes");
                datatable.addCell("No");
                datatable.addCell("Yes");
                datatable.addCell("No");
                datatable.addCell("Yes");
               
            }
            document.add(new Paragraph("com.lowagie.text.Table - Cells split"));
            document.add(datatable);
            document.newPage();
            document.add(new Paragraph("com.lowagie.text.pdf.PdfPTable - Cells split\n\n"));
            datatable.setConvert2pdfptable(true);
            document.add(datatable);
            document.newPage();
            document.add(new Paragraph("com.lowagie.text.Table - Cells kept together"));
            datatable.setConvert2pdfptable(false);
            datatable.setCellsFitPage(true);
            document.add(datatable);
            document.newPage();
            document.add(new Paragraph("com.lowagie.text.pdf.PdfPTable - Cells kept together\n\n"));
            datatable.setConvert2pdfptable(true);
            document.add(datatable);
        }
        catch(Exception e) {
            e.printStackTrace();
        }
       
        // we close the document
        document.close();
    }
View Full Code Here

     */
    public static void main(String[] args) {
       
        System.out.println("Transformations");       
        // 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("transformations.pdf"));
           
            // step 3: we open the document
            document.open();
           
            // step 4:
            PdfContentByte cb = writer.getDirectContent();
           
            // we create a PdfTemplate
            PdfTemplate template = cb.createTemplate(120, 120);
           
            // we add some graphics
            template.moveTo(30, 10);
            template.lineTo(90, 10);
            template.lineTo(90, 80);
            template.lineTo(110, 80);
            template.lineTo(60, 110);
            template.lineTo(10, 80);
            template.lineTo(30, 80);
            template.closePath();
            template.stroke();
            template.sanityCheck();
           
            // we add the template on different positions
            cb.addTemplate(template, 0, 0);
            cb.addTemplate(template, 0, 1, -1, 0, 200, 600);
            cb.addTemplate(template, .5f, 0, 0, .5f, 100, 400);
            cb.sanityCheck();
           
            // we go to a new page
            document.newPage();
            cb.addTemplate(template, 0, 500);
            cb.addTemplate(template, 2, 0, -1, 2, 200, 300);
            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

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.