com.asprise.util.pdf
Class PDFImageWriter

java.lang.Object
  extended bycom.asprise.util.pdf.PDFImageWriter

public class PDFImageWriter
extends java.lang.Object

An easy-to-use utility class that can create PDF document from images. Sample code:

  1. Basic usage: Write image from files to PDF
    
     PDFImageWriter writer = new PDFImageWriter(new FileOutputStream("new.pdf"));
     writer.open();
     writer.addImage("C:\\1.jpg");
     writer.addImage("C:\\2.png");
     writer.close();
     System.out.println("DONE.");
     
  2. or by using the utility function: - one line only
    
     PDFImageWriter.saveImagesToPDF(new File[]{ new File("C:\\1.jpg"), new File("C:\\2.png") }, new File("new.pdf");
     
  3. Save java.awt.Image into PDF
    
     PDFImageWriter.saveImagesToPDF(new Image[]{image1, image2}, new File("new.pdf");
     
  4. Optionally, you can control the security settings of the PDF
    
     PDFSecurityObject so = new PDFSecurityObject();
     so.ownerPassword = "LAB Asprise";
     so.userPassword = "user";
     so.permissions = PDFSecurityObject.PERMISSION_PRINTING | PDFSecurityObject.PERMISSION_COPY; // allow printing and copying.
     
     PDFImageWriter writer = new PDFImageWriter(new FileOutputStream("new.pdf"));
     writer.setPDFSecurityObject(so);
     writer.open();
     writer.addImage("C:\\1.jpg");
     writer.close();
     


Constructor Summary
PDFImageWriter(java.io.OutputStream outputStream)
          Creates a writer with the specified target output stream.
 
Method Summary
 void addImage(java.io.File imageFile)
          Adds the given image as a PDF page.
 void addImage(java.awt.Image image)
          Adds the given image as a PDF page.
 void addImage(java.lang.String imageFilePath)
          Adds the given image as a PDF page.
 void close()
          Signal the writer to write content to the target output stream and close the writer.
 PDFSecurityObject getPdfSecurityObject()
          Returns the PDF security object used.
static void main(java.lang.String[] args)
          A utility that save images into PDF file.
 void open()
          Opens the writer for adding contents.
static void saveImagesToPDF(java.io.File[] sourceImages, java.io.File targetPDFile)
          Saves the given images into the specified PDF file.
static void saveImagesToPDF(java.awt.Image[] sourceImages, java.io.File targetPDFile)
          Saves the given images into the specified PDF file.
 void setPDFSecurityObject(PDFSecurityObject pdfSecurityObject)
          Sets the PDF security to be used - you need to set security object before close() otherwise it will be ignored.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PDFImageWriter

public PDFImageWriter(java.io.OutputStream outputStream)
Creates a writer with the specified target output stream.

Parameters:
outputStream -
Method Detail

addImage

public void addImage(java.lang.String imageFilePath)
              throws java.io.IOException
Adds the given image as a PDF page. Supported images formats are: GIF, PNG, BMP, JPEG.

Throws:
java.io.IOException

addImage

public void addImage(java.io.File imageFile)
              throws java.io.IOException
Adds the given image as a PDF page. Supported images formats are: GIF, PNG, BMP, JPEG.

Parameters:
imageFile - - this image file.
Throws:
java.io.IOException

addImage

public void addImage(java.awt.Image image)
Adds the given image as a PDF page.


open

public void open()
Opens the writer for adding contents.


close

public void close()
Signal the writer to write content to the target output stream and close the writer.


saveImagesToPDF

public static void saveImagesToPDF(java.io.File[] sourceImages,
                                   java.io.File targetPDFile)
                            throws java.io.IOException
Saves the given images into the specified PDF file.

Parameters:
sourceImages - - Supported images formats are: GIF, PNG, BMP, JPEG.
targetPDFile -
Throws:
java.io.IOException

saveImagesToPDF

public static void saveImagesToPDF(java.awt.Image[] sourceImages,
                                   java.io.File targetPDFile)
                            throws java.io.IOException
Saves the given images into the specified PDF file.

Parameters:
sourceImages -
targetPDFile -
Throws:
java.io.IOException

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
A utility that save images into PDF file. Usage: java com.asprise.util.pdf.PDFImageWriter [target pdf File] [source image file 1] [source image file 2 ...]

Parameters:
args -
Throws:
java.lang.Exception

getPdfSecurityObject

public PDFSecurityObject getPdfSecurityObject()
Returns the PDF security object used.

Returns:

setPDFSecurityObject

public void setPDFSecurityObject(PDFSecurityObject pdfSecurityObject)
Sets the PDF security to be used - you need to set security object before close() otherwise it will be ignored.

Parameters:
pdfSecurityObject -