Package com.lowagie.text.pdf

Examples of com.lowagie.text.pdf.PdfWriter


    LwgDocument document = new LwgDocument();

    try {

      // step 2:
      PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(
          "ChainedActions.pdf"));
      // step 3: we add Javascript as Metadata and we open the document       
      document.open();
      // step 4: we add some content
      PdfAction action = PdfAction.javaScript("app.alert('Welcome at my site');\r", writer);
View Full Code Here


    // step 1: creation of a document-object
    LwgDocument document = new LwgDocument();
    try {
      // step 2:
      PdfWriter writer = PdfWriter.getInstance(document,
          new FileOutputStream("Layers.pdf"));
      writer.setPdfVersion(PdfWriter.VERSION_1_5);
      // step 3:
      writer.setViewerPreferences(PdfWriter.PageModeUseOC);
      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();
      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());
View Full Code Here

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

      // step 2:
      PdfWriter writer = PdfWriter.getInstance(document,
          new FileOutputStream("Annotations.pdf"));
      // step 3:
      writer.setPdfVersion(PdfWriter.VERSION_1_5);
      document.open();
      // step 4:
      PdfContentByte cb = writer.getDirectContent();
      // page 1
            PdfFileSpecification fs = PdfFileSpecification.fileExtern(writer, "cards.mpg");
            writer.addAnnotation(PdfAnnotation.createScreen(writer, new LwgRectangle(200f, 700f, 300f, 800f), "cards.mpg",fs,"video/mpeg",true));
      PdfAnnotation a = new PdfAnnotation(writer, 200f, 550f, 300f, 650f,
          PdfAction.javaScript("app.alert('Hello');\r", writer));
      document.add(new Chunk("click to trigger javascript").setAnnotation(a).setLocalDestination("top"));
      writer.addAnnotation(a);
      writer.addAnnotation(PdfAnnotation.createFileAttachment(writer, new LwgRectangle(100f, 650f, 150f, 700f), "This is some text", "some text".getBytes(), null, "some.txt"));
      writer.addAnnotation(PdfAnnotation.createText(writer, new LwgRectangle(200f, 400f, 300f, 500f), "Help", "This Help annotation was made with 'createText'", false, "Help"));
      writer.addAnnotation(PdfAnnotation.createText(writer, new LwgRectangle(200f, 250f, 300f, 350f), "Help", "This Comment annotation was made with 'createText'", true, "Comment"));
      cb.rectangle(200, 700, 100, 100);
      cb.rectangle(200, 550, 100, 100);
      cb.rectangle(200, 400, 100, 100);
      cb.rectangle(200, 250, 100, 100);
      cb.stroke();
      document.newPage();
      // page 2
      writer.addAnnotation(PdfAnnotation.createLink(writer, new LwgRectangle(200f, 700f, 300f, 800f), PdfAnnotation.HIGHLIGHT_TOGGLE, PdfAction.javaScript("app.alert('Hello');\r", writer)));
      writer.addAnnotation(PdfAnnotation.createLink(writer, new LwgRectangle(200f, 550f, 300f, 650f), PdfAnnotation.HIGHLIGHT_OUTLINE, "top"));
      writer.addAnnotation(PdfAnnotation.createLink(writer, new LwgRectangle(200f, 400f, 300f, 500f), PdfAnnotation.HIGHLIGHT_PUSH, 1, new PdfDestination(PdfDestination.FIT)));
      writer.addAnnotation(PdfAnnotation.createSquareCircle(writer, new LwgRectangle(200f, 250f, 300f, 350f), "This Comment annotation was made with 'createSquareCircle'", false));
      document.newPage();
      // page 3
      PdfContentByte pcb = new PdfContentByte(writer);
      pcb.setColorFill(new Color(0xFF, 0x00, 0x00));
      writer.addAnnotation(PdfAnnotation.createFreeText(writer, new LwgRectangle(200f, 700f, 300f, 800f), "This is some free text, blah blah blah", pcb));
      writer.addAnnotation(PdfAnnotation.createLine(writer, new LwgRectangle(200f, 550f, 300f, 650f), "this is a line", 200, 550, 300, 650));
      writer.addAnnotation(PdfAnnotation.createStamp(writer, new LwgRectangle(200f, 400f, 300f, 500f), "This is a stamp", "Stamp"));
      writer.addAnnotation(PdfAnnotation.createPopup(writer, new LwgRectangle(200f, 250f, 300f, 350f), "Hello, I'm a popup!", true));
      cb.rectangle(200, 700, 100, 100);
      cb.rectangle(200, 550, 100, 100);
      cb.rectangle(200, 250, 100, 100);
      cb.stroke();
     
View Full Code Here

      // step 1: creation of a document-object
      LwgDocument document = new LwgDocument(LwgPageSize.A4);
      try
      {
         // step 2:
         PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(fle));
         // step 3:
         //writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
         document.open();
         // step 4: we grab the ContentByte and do some stuff with it
         writer.setPageEvent(new GfrDemoJfcAndTextDemo());

         LwgFont font9 = FontFactory.getFont(FontFactory.HELVETICA, 9);
         LwgFont font15 = FontFactory.getFont(FontFactory.HELVETICA, 15);
         font15.setStyle(Markup.CSS_VALUE_BOLD);
View Full Code Here

    LwgDocument document = new LwgDocument();
    try {
      // step 2:
      // we create a writer that listens to the document
      // and directs a PDF-stream to System.out (and a txt file)
      PdfWriter w = PdfWriter.getInstance(document, System.out);
      w.setCloseStream(false); // System.out should not be closed
      PdfWriter.getInstance(document,
          new FileOutputStream("HelloWorld.txt"));

      // step 3: we open the document
      document.open();
View Full Code Here

    LwgDocument document = new LwgDocument();
    LwgDocument remote = new LwgDocument();
    try {

      // step 2:
      PdfWriter writer = PdfWriter.getInstance(document,
          new FileOutputStream("Actions.pdf"));
      PdfWriter.getInstance(remote, new FileOutputStream("remote.pdf"));
      // step 3:
      document.open();
      remote.open();
      // step 4: we add some content
      PdfAction action = PdfAction.gotoLocalPage(2, new PdfDestination(
          PdfDestination.XYZ, -1, 10000, 0), writer);
      writer.setOpenAction(action);
      document.add(new Paragraph("Page 1"));
      document.newPage();
      document.add(new Paragraph("Page 2"));
      document.add(new Chunk("goto page 1").setAction(PdfAction
          .gotoLocalPage(1, new PdfDestination(PdfDestination.FITH,
View Full Code Here

    LwgDocument document = new LwgDocument();

    try {

      // step 2:
      PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(
          "JavaScriptAction.pdf"));
      // step 3: we add Javascript as Metadata and we open the document       
      document.open();
      // step 4: we add some content
      Paragraph p = new Paragraph(new Chunk("Click to say Hello")
View Full Code Here

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

      // step 3: we open the document
      document.open();
      // step 4:
      LwgFont red = FontFactory.getFont(FontFactory.HELVETICA, LwgFont.DEFAULTSIZE, LwgFont.BOLD, new Color(0xFF, 0x00, 0x00));
      LwgFont blue = FontFactory.getFont(FontFactory.HELVETICA, LwgFont.DEFAULTSIZE, LwgFont.ITALIC, new Color(0x00, 0x00, 0xFF));
      Paragraph p;
      p = new Paragraph("Roses are ");
      p.add(new Chunk("red", red));
      document.add(p);
      p = new Paragraph("Violets are ");
      p.add(new Chunk("blue", blue));
      document.add(p);
      BaseFont bf = FontFactory.getFont(FontFactory.COURIER).getCalculatedBaseFont(false);
      PdfContentByte cb = writer.getDirectContent();
      cb.beginText();
      cb.setColorFill(new Color(0x00, 0xFF, 0x00));
      cb.setFontAndSize(bf, 12);
      cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "Grass is green", 250, 700, 0);
      cb.endText();
View Full Code Here

    // step 1: creation of a document-object
    LwgDocument document = new LwgDocument();
    try {
      // step 2:
      // we create 3 different writers that listen to the document
      PdfWriter pdf = PdfWriter.getInstance(document,
          new FileOutputStream("HelloWorldPdf.pdf"));
      RtfWriter2 rtf = RtfWriter2.getInstance(document,
          new FileOutputStream("HelloWorldRtf.rtf"));
      HtmlWriter.getInstance(document,
          new FileOutputStream("HelloWorldHtml.html"));

      // step 3: we open the document
      document.open();
      // step 4: we add a paragraph to the document
      document.add(new Paragraph("Hello World"));
      // we make references
      Anchor pdfRef = new Anchor("see Hello World in PDF.");
      pdfRef.setReference("./HelloWorldPdf.pdf");
      Anchor rtfRef = new Anchor("see Hello World in RTF.");
      rtfRef.setReference("./HelloWorldRtf.rtf");
     
      // we add the references, but only to the HTML page:
     
      pdf.pause();
      rtf.pause();
      document.add(pdfRef);
      document.add(Chunk.NEWLINE);
      document.add(rtfRef);
      pdf.resume();
      rtf.resume();
     
    } catch (DocumentException de) {
      System.err.println(de.getMessage());
    } catch (IOException ioe) {
View Full Code Here

           
        // step 1: creation of a document-object
        LwgDocument document = new LwgDocument(LwgPageSize.LETTER, 90, 54, 72, 72);
        try {
            // step 2: we create a writer that listens to the document
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("columnobjects.pdf"));
           
            float gutter = 20;
            int numColumns = 3;
            float fullWidth = document.right() - document.left();
            float columnWidth = (fullWidth - (numColumns - 1) * gutter) / numColumns;
            float allColumns[] = new float[numColumns]; // left
            for (int k = 0; k < numColumns; ++k) {
                allColumns[k] = document.left() + (columnWidth + gutter) * k;
            }
            // set the fonts
            LwgFont font24B = FontFactory.getFont(FontFactory.TIMES_ROMAN, 24, LwgFont.BOLD);
            LwgFont font10B = FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, LwgFont.BOLD);
            LwgFont font14B = FontFactory.getFont(FontFactory.TIMES_ROMAN, 14, LwgFont.BOLD, new Color(255, 0, 0));
            LwgFont font9 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 9);
            LwgFont font11 = FontFactory.getFont(FontFactory.TIMES_ROMAN, 11);
           
            // step 3: we open the document
            document.open();           
            // step 4:
            // get the stream content
            PdfContentByte cb = writer.getDirectContent();
            // headers
            LwgPhrase fullTitle = new LwgPhrase("Full Title", font24B);
            float currentY = document.top();
            ColumnText ct = new ColumnText(cb);
            ct.setSimpleColumn(fullTitle, document.left(), 0, document.right(), document.top(), 24, LwgElement.ALIGN_JUSTIFIED);
View Full Code Here

TOP

Related Classes of com.lowagie.text.pdf.PdfWriter

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.