com.cete.dynamicpdf.pageelements
Class BackgroundImage


Example: The following example will place an image on the page making it the background for that page.

import com.cete.dynamicpdf.*;
import com.cete.dynamicpdf.pageelements.*;
 
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);
          
          // Create a background image
          BackgroundImage backgroundImage = null;
          try {
              backgroundImage = new BackgroundImage("[PhysicalPath]/MyImage.jpg");
          }catch(FileNotFoundException e){}
          
          // Place the image with in the page margins
          backgroundImage.setUseMargins(true);
          
          // Add the background image to the page
          page.getElements().add(backgroundImage);    

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