com.cete.dynamicpdf
Class Document



Examples Description
Example 1 This example shows how to use the document in the creation of a simple PDF document.
Example 2 This example shows how to output the PDF to a byte array.
Example 3 This example shows how to output the PDF to a file.
Example 4 This example shows how to output the document to a memory stream object.
Example 5 This example shows how to output the document to the current web page and to a pdf file.
Example 6 This example shows how to output the document to the current web page and shows dialog box whether to save or not.
Example 7 This example shows how to output the document to the current web page and specifies whether browser to cache or not.
Example 8 This example shows how to output the document to the current web page.
Example 9 This example shows how to create an Xmp Metadata and Add it to the document.


Example 1 : This example shows how to use the document in the creation of a simple PDF document.

  import com.cete.dynamicpdf.*;
  import com.cete.dynamicpdf.pageelements.Label;

  public class MyClass {
    public static void Main(String args[]) {

          // Create a PDF Document
          Document document = new Document();

          // Create a Page and add it to the document
          Page page = new Page();
          document.getPages().add(page);

          // Add a label to the page
          page.getElements().add(new Label("My PDF Document", 0,
          0, 512, 40, Font.getHelvetica(), 30, TextAlign.CENTER));

          // Save the PDF document
         document.draw("[PhysicalPath]/MyDocument.pdf");
    }
  } 

Top

EXample 2 : This example shows how to output the PDF to a byte array.
    
    import com.cete.dynamicpdf.*;
    import com.cete.dynamicpdf.pageelements.Label;

    public class MyClass {
      public static void Main(String args[]) {

          // Create a PDF Document
          Document document = new Document();

          // Create a Page and add it to the document
          Page page = new Page();
          document.getPages().add(page);

          // Add a label to the page 
	  Page.getElements().add( new Label( "My PDF Document", 0, 0, 512, 40, Font.getHelvetica(), 30, TextAlign.CENTER ) );

        // Save the PDF document to a byte array
        byte[] pdfData = document.draw();
    }
  } 

Top

Example 3 : This example shows how to output the PDF to a file.
  
  import com.cete.dynamicpdf.*;
  import com.cete.dynamicpdf.pageelements.Label;

  public class MyClass {
    public static void Main(String args[]) {

          // Create a PDF Document
          Document document = new Document();

          // Create a Page and add it to the document
          Page page = new Page();
          document.getPages().add(page);

          // Add a label to the page 
          Page.getElements().add( new Label( "My PDF Document", 0, 0, 512, 40, Font.getHelvetica(), 30, TextAlign.CENTER ) );
  
          // Save the PDF document
         document.draw("[Physicalpath]\MyDocument.pdf");
    }
}

Top

Example 4 : This example shows how to output the document to a memory stream object.
 
  import com.cete.dynamicpdf.*;
  import com.cete.dynamicpdf.pageelements.Label;

  public class MyClass {
    public static void Main(String args[]) {

          // Create a PDF Document
          Document document = new Document();

          // Create a Page and add it to the document
          Page page = new Page();
          document.getPages().add(page);

          // Add a label to the page 
          Page.getElements().add( new Label( "My PDF Document", 0, 0, 512, 40, Font.getHelvetica(), 30, TextAlign.CENTER ) );
 
	  // Create a memory stream object to save to
          ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        
          // Output the PDF to the MemoryStream
          document.draw(outputStream);
    }
  }

Top

Example 5 : This Example shows to Output the document to current web page and to a pdf file.

  import com.cete.dynamicpdf.*;
  import com.cete.dynamicpdf.pageelements.Label;
  import java.io.IOException;
  import javax.servlet.ServletConfig;
  import javax.servlet.ServletException;
  import javax.servlet.ServletOutputStream;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;

  public class HelloWorld  extends HttpServlet {
    
    ServletOutputStream sOut;
    
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
    }
    
    public void doGet(HttpServletRequest req, HttpServletResponse res)
                     throws IOException,ServletException {
               
        sOut = res.getOutputStream();
        // Create a document and set it's properties
        Document objDocument = new Document();
        objDocument.setCreator("HelloWorld.java");
        objDocument.setAuthor("Your Name");
        objDocument.setTitle("Hello World");
        
        // Create a page to add to the document
        Page objPage = new Page(PageSize.LETTER, PageOrientation.PORTRAIT,54.0f);
               
        // Create a Label to add to the page
        String strText = "Hello World...\nFrom DynamicPDF Generator " +
                         "for Java\nDynamicPDF.com";
        Label objLabel = new Label(strText, 0, 0, 504, 100, Font.getHelvetica(),
                                 18, TextAlign.CENTER);
        
        // Add label to page
        objPage.getElements().add(objLabel);
        
        // Add page to document
        objDocument.getPages().add(objPage);
        
        // Outputs the document to current web page.
        objDocument.drawToWeb(req, res , sOut, "[physicalpath]/HelloWorld.pdf");
        sOut.close();
    }
  }

Top

Example 6 : This Example shows to Output the document to current web page and shows dialog box whether to save or not.

  import com.cete.dynamicpdf.*;
  import com.cete.dynamicpdf.pageelements.Label;
  import java.io.IOException;
  import javax.servlet.ServletConfig;
  import javax.servlet.ServletException;
  import javax.servlet.ServletOutputStream;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;

  public class HelloWorld  extends HttpServlet {
    
    ServletOutputStream sOut;
    
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
    }
    
    public void doGet(HttpServletRequest req, HttpServletResponse res)
                     throws IOException,ServletException {
               
        sOut = res.getOutputStream();
        // Create a document and set it's properties
        Document objDocument = new Document();
        objDocument.setCreator("HelloWorld.java");
        objDocument.setAuthor("Your Name");
        objDocument.setTitle("Hello World");
        
        // Create a page to add to the document
        Page objPage = new Page(PageSize.LETTER, PageOrientation.PORTRAIT,54.0f);
               
        // Create a Label to add to the page
        String strText = "Hello World...\nFrom DynamicPDF Generator " +
                         "for Java\nDynamicPDF.com";
        Label objLabel = new Label(strText, 0, 0, 504, 100, Font.getHelvetica(),
                                 18, TextAlign.CENTER);
        
        // Add label to page
        objPage.getElements().add(objLabel);
        
        // Add page to document
        objDocument.getPages().add(objPage);
        
        // Outputs the document to current web page.
        objDocument.drawToWeb(req, res , sOut, "[physicalpath]/HelloWorld.pdf",true);
        sOut.close();
    }
  }

Top

Example 7 : This Example shows to Output the document to current web page and specificies whether browser has to cache or not.

  import com.cete.dynamicpdf.*;
  import com.cete.dynamicpdf.pageelements.Label;
  import java.io.IOException;
  import javax.servlet.ServletConfig;
  import javax.servlet.ServletException;
  import javax.servlet.ServletOutputStream;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;

  public class HelloWorld  extends HttpServlet {
    
    ServletOutputStream sOut;
    
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
    }
    
    public void doGet(HttpServletRequest req, HttpServletResponse res)
                     throws IOException,ServletException {
               
        sOut = res.getOutputStream();
        // Create a document and set it's properties
        Document objDocument = new Document();
        objDocument.setCreator("HelloWorld.java");
        objDocument.setAuthor("Your Name");
        objDocument.setTitle("Hello World");
        
        // Create a page to add to the document
        Page objPage = new Page(PageSize.LETTER, PageOrientation.PORTRAIT,54.0f);
               
        // Create a Label to add to the page
        String strText = "Hello World...\nFrom DynamicPDF Generator " +
                         "for Java\nDynamicPDF.com";
        Label objLabel = new Label(strText, 0, 0, 504, 100, Font.getHelvetica(),
                                 18, TextAlign.CENTER);
        
        // Add label to page
        objPage.getElements().add(objLabel);
        
        // Add page to document
        objDocument.getPages().add(objPage);
        
        // Outputs the document to current web page.
        objDocument.drawToWeb(req, res , sOut,true);
        sOut.close();
    }
  }

Top

Example 8 : This Example shows to Output the document to current web page.

  import com.cete.dynamicpdf.*;
  import com.cete.dynamicpdf.pageelements.Label;
  import java.io.IOException;
  import javax.servlet.ServletConfig;
  import javax.servlet.ServletException;
  import javax.servlet.ServletOutputStream;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;

  public class HelloWorld  extends HttpServlet {
    
    ServletOutputStream sOut;
    
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
    }
    
    public void doGet(HttpServletRequest req, HttpServletResponse res)
                     throws IOException,ServletException {
               
        sOut = res.getOutputStream();
        // Create a document and set it's properties
        Document objDocument = new Document();
        objDocument.setCreator("HelloWorld.java");
        objDocument.setAuthor("Your Name");
        objDocument.setTitle("Hello World");
        
        // Create a page to add to the document
        Page objPage = new Page(PageSize.LETTER, PageOrientation.PORTRAIT,54.0f);
               
        // Create a Label to add to the page
        String strText = "Hello World...\nFrom DynamicPDF Generator " +
                         "for Java\nDynamicPDF.com";
        Label objLabel = new Label(strText, 0, 0, 504, 100, Font.getHelvetica(),
                                 18, TextAlign.CENTER);
        
        // Add label to page
        objPage.getElements().add(objLabel);
        
        // Add page to document
        objDocument.getPages().add(objPage);
        
        // Outputs the document to current web page.
        objDocument.drawToWeb(req, res , sOut);
        sOut.close();
    }
  }

Top

Example 9 : This example shows how to create an Xmp Metadata and Add it to the document.
import com.cete.dynamicpdf.*; public class MyClass { public static void Main(String args[]) { // Create a PDF Document Document document = new Document(); // Add blank pages to the document document.getPages().add( new Page( PageSize.LETTER ) ); document.getPages().add( new Page( PageSize.LETTER ) ); // Create an Xmp Metadata XmpMetadata xmp = new XmpMetadata(); // Add the Xmp Metadata to the document document.setXmpMetadata( xmp ); // Save the PDF document document.draw("[PhysicalPath]/MyDocument.pdf"); } } }

Top