Package com.lowagie.text

Examples of com.lowagie.text.LwgDocument


       
        System.out.println("Literal PDF Syntax");
        LwgDocument.compress = false;
       
        // 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("literal.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();
            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";
            cb.setLiteral(star);
           
            // sanityCheck doesn't check literals.
            //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


  public static void main(String[] args) {

    System.out.println("Romeo and Juliet");

    // step 1: creation of a document-object
    LwgDocument document = new LwgDocument(LwgPageSize.A4, 80, 50, 30, 65);

    try {
      // step 2:
      // we create a writer that listens to the document
      // and directs a XML-stream to a file
      PdfWriter writer = PdfWriter.getInstance(document,
          new FileOutputStream("RomeoJuliet.pdf"));

      // create add the event handler
      MyPageEvents events = new Events().getPageEvents();
      writer.setPageEvent(events);

      // step 3: we create a parser and set the document handler
      SAXParser parser = SAXParserFactory.newInstance().newSAXParser();

      // step 4: we parse the document
      parser.parse("playRomeoJuliet.xml", new Events().getXmlHandler(document));

      document.newPage();
      Speaker speaker;
      for (Iterator i = events.getSpeakers().iterator(); i.hasNext();) {
        speaker = (Speaker) i.next();
        document.add(new Paragraph(speaker.getName() + ": "
            + speaker.getOccurrence() + " speech blocks"));
      }
      document.close();

    } catch (Exception e) {
      e.printStackTrace();
      System.err.println(e.getMessage());
    }
View Full Code Here

   */
  public static void main(String[] args) {
    System.out.println("Changing the Graphics State with PdfGState");

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

            PdfGState gs = new PdfGState();
            gs.setFillOpacity(0.5f);
            cb.setGState(gs);
      cb.setColorFill(Color.red);
      cb.circle(260.0f, 500.0f, 250.0f);
      cb.fill();
      cb.circle(260.0f, 500.0f, 200.0f);
      cb.fill();
      cb.circle(260.0f, 500.0f, 150.0f);
      cb.fill();
      gs.setFillOpacity(0.2f);
      cb.setGState(gs);
      cb.setColorFill(Color.blue);
      cb.circle(260.0f, 500.0f, 100.0f);
      cb.fill();
      cb.circle(260.0f, 500.0f, 50.0f);
      cb.fill();
     
      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

  public static void main(String[] args) {

    System.out.println("Rendering");

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

      // step 3: we open the document
      document.open();
      // step 4:     
      Paragraph p = new Paragraph("Text Rendering:");
      document.add(p);
      Chunk chunk = new Chunk("rendering test");
      chunk.setTextRenderMode(PdfContentByte.TEXT_RENDER_MODE_FILL, 100f, new Color(0xFF, 0x00, 0x00));
      document.add(chunk);
      document.add(Chunk.NEWLINE);
      chunk.setTextRenderMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE, 0.3f, new Color(0xFF, 0x00, 0x00));
      document.add(chunk);
      document.add(Chunk.NEWLINE);
      chunk.setTextRenderMode(PdfContentByte.TEXT_RENDER_MODE_INVISIBLE, 100f, new Color(0x00, 0xFF, 0x00));
      document.add(chunk);
      document.add(Chunk.NEWLINE);
      chunk.setTextRenderMode(PdfContentByte.TEXT_RENDER_MODE_STROKE, 0.3f, new Color(0x00, 0x00, 0xFF));
      document.add(chunk);
      document.add(Chunk.NEWLINE);
      Chunk bold = new Chunk("This looks like Font.BOLD");
      bold.setTextRenderMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE, 0.5f, new Color(0x00, 0x00, 0x00));
      document.add(bold);
     
    } 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

     * @param args Unused
     */
    public static void main(String[] args) {
        System.out.println("Demonstrates adding a soft linebreak to a Paragraph");
        try {
            LwgDocument document = new LwgDocument();
            RtfWriter2.getInstance(document, new FileOutputStream("SoftLineBreak.rtf"));

            document.open();

            document.add(new Paragraph("This is just a paragraph."));
           
            Paragraph par = new Paragraph();

            // Set the spacings just to demonstrate that the soft linebreak
            // does not cause spacing before or after
            par.setSpacingBefore(10);
            par.setSpacingAfter(10);
           
            // Add the contents before the linebreak
            par.add("This paragraph contains a soft linebreak");

            // Add the soft linebreak
            par.add(RtfDirectContent.DIRECT_SOFT_LINEBREAK);

            // Add the contents after the linebreak
            par.add("just before the just.");
           
            // Add the paragraph to the document
            document.add(par);

            document.add(new Paragraph("This is just a paragraph."));
           
            document.close();
        } catch (FileNotFoundException fnfe) {
            fnfe.printStackTrace();
        } catch (DocumentException de) {
            de.printStackTrace();
        }
View Full Code Here

     */
    public static void main(String[] args) {
        System.out.println("Grouping optional content");
        try {
          // step 1
            LwgDocument document = new LwgDocument(LwgPageSize.A4, 50, 50, 50, 50);
            // step 2
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("contentgroups.pdf"));
            writer.setPdfVersion(PdfWriter.VERSION_1_5);
            writer.setViewerPreferences(PdfWriter.PageModeUseOC);
            // step 3
            document.open();
            // step 4
            PdfContentByte cb = writer.getDirectContent();
            LwgPhrase explanation = new LwgPhrase("Layer grouping", new LwgFont(LwgFont.HELVETICA, 20, LwgFont.BOLD, Color.red));
            ColumnText.showTextAligned(cb, LwgElement.ALIGN_LEFT, explanation, 50, 650, 0);
            PdfLayer l1 = new PdfLayer("Layer 1", writer);
            PdfLayer l2 = new PdfLayer("Layer 2", writer);
            PdfLayer l3 = new PdfLayer("Layer 3", writer);
            PdfLayerMembership m1 = new PdfLayerMembership(writer);
            m1.addMember(l2);
            m1.addMember(l3);
            LwgPhrase p1 = new LwgPhrase("Text in layer 1");
            LwgPhrase p2 = new LwgPhrase("Text in layer 2 or layer 3");
            LwgPhrase p3 = new LwgPhrase("Text in layer 3");
            cb.beginLayer(l1);
            ColumnText.showTextAligned(cb, LwgElement.ALIGN_LEFT, p1, 50, 600, 0);
            cb.endLayer();
            cb.beginLayer(m1);
            ColumnText.showTextAligned(cb, LwgElement.ALIGN_LEFT, p2, 50, 550, 0);
            cb.endLayer();
            cb.beginLayer(l3);
            ColumnText.showTextAligned(cb, LwgElement.ALIGN_LEFT, p3, 50, 500, 0);
            cb.endLayer();
            cb.sanityCheck();
           
            PdfOCProperties p = writer.getOCProperties();
            PdfArray order = new PdfArray();
            order.add(l1.getRef());
            PdfArray group = new PdfArray();
            group.add(new PdfString("A group of two", PdfObject.TEXT_UNICODE));
            group.add(l2.getRef());
            group.add(l3.getRef());
            order.add(group);
            PdfDictionary d = new PdfDictionary();
            d.put(PdfName.ORDER, order);
            p.put(PdfName.D, d);
            // step 5
            document.close();
        }
        catch(Exception de) {
            de.printStackTrace();
        }
    }
View Full Code Here

     */
    public static void main(String[] args) {
       
        System.out.println("Affine Transformation");       
        // 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("affinetransformation.pdf"));
           
            // step 3: we open the document
            document.open();
           
            // step 4:
            PdfContentByte cb = writer.getDirectContent();
            cb.transform(AffineTransform.getScaleInstance(1.2, 0.75));
           
            // we create a PdfTemplate
            PdfTemplate template = cb.createTemplate(25, 25);
           
            // we add some crosses to visualize the coordinates
            template.moveTo(13, 0);
            template.lineTo(13, 25);
            template.moveTo(0, 13);
            template.lineTo(50, 13);
            template.stroke();
            template.sanityCheck();
           
            // we add the template on different positions
            cb.addTemplate(template, 216 - 13, 720 - 13);
            cb.addTemplate(template, 360 - 13, 360 - 13);
            cb.addTemplate(template, 360 - 13, 504 - 13);
            cb.addTemplate(template, 72 - 13, 144 - 13);
            cb.addTemplate(template, 144 - 13, 288 - 13);

            cb.moveTo(216, 720);
            cb.lineTo(360, 360);
            cb.lineTo(360, 504);
            cb.lineTo(72, 144);
            cb.lineTo(144, 288);
            cb.stroke();
           
            BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
            cb.beginText();
            cb.setFontAndSize(bf, 12);
            cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "(3\" * 1.2, 10\" * .75)", 216 + 25, 720 + 5, 0);
            cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "(5\" * 1.2, 5\" * .75)", 360 + 25, 360 + 5, 0);
            cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "(5\" * 1.2, 7\" * .75)", 360 + 25, 504 + 5, 0);
            cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "(1\" * 1.2, 2\" * .75)", 72 + 25, 144 + 5, 0);
            cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "(2\" * 1.2, 4\" * .75)", 144 + 25, 288 + 5, 0);
            cb.endText();
           
            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

    public static void main(String[] args) {
       
        System.out.println("Drawing circles");
       
        // step 1: creation of a document-object
        LwgDocument document = new LwgDocument();
       
        try {
           
            // step 2: creation of the writer
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("circles.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();

            cb.circle(250.0f, 500.0f, 200.0f);
            cb.circle(250.0f, 500.0f, 150.0f);
            cb.stroke();
            cb.setRGBColorFill(0xFF, 0x00, 0x00);
            cb.circle(250.0f, 500.0f, 100.0f);
            cb.fillStroke();
            cb.setRGBColorFill(0xFF, 0xFF, 0xFF);
            cb.circle(250.0f, 500.0f, 50.0f);
            cb.fill();
           
            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

  public static void main(String[] args) {

    System.out.println("Generic");

    // step 1: creation of a document-object
    LwgDocument document = new LwgDocument();
    try {
      // step 2:
      // we create a writer that listens to the document
      PdfWriter writer = PdfWriter.getInstance(document,
          new FileOutputStream("Generic.pdf"));
      writer.setPageEvent(new Generic());
     
      // step 3: we open the document
      document.open();
      // step 4:
      Paragraph p = new Paragraph("Generic page event");
      document.add(p);
      Chunk box = new Chunk("box");
      box.setGenericTag("box");
      Chunk ellipse = new Chunk("ellipse");
      ellipse.setGenericTag("ellipse");
      p = new Paragraph("In this example, we will add chunks that are tagged as an ");
      p.add(ellipse);
      p.add(" and chunks that are tagged as a ");
      p.add(box);
      p.add(". Can you see the difference between ");
      Chunk c1 = new Chunk("this");
      c1.setGenericTag("box");
      Chunk c2 = new Chunk("that");
      c2.setGenericTag("ellipse");
      p.add(c1);
      p.add(" and ");
      p.add(c2);
      p.add("? One is a ");
      p.add(box);
      p.add("; the other an ");
      p.add(ellipse);
      document.add(p);
    } 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

     * @param args no arguments needed
     */
    public static void main(String[] args) {
    System.out.println("SoftMask");
        // 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("softmask.pdf"));
            // step 3: we open the document
            document.open();
            // step 4: content
            PdfContentByte cb = writer.getDirectContent();
            String text = "text ";
            text += text;
            text += text;
            text += text;
            text += text;
            text += text;
            text += text;
            text += text;
            text += text;
            document.add(new Paragraph(text));
            LwgImage img = LwgImage.getInstance("otsoe.jpg");
            img.setAbsolutePosition(100, 550);
            byte gradient[] = new byte[256];
            for (int k = 0; k < 256; ++k)
                gradient[k] = (byte)k;
            LwgImage smask = LwgImage.getInstance(256, 1, 1, 8, gradient);
            smask.makeMask();
            img.setImageMask(smask);
            cb.addImage(img);
            cb.sanityCheck();
        }
        catch (Exception de) {
            de.printStackTrace();
        }
        // 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.