The simplified code:

==============

 

public static synchronized ByteArrayOutputStream getRatioListPDF(File file,

      Object graph) throws

      DocumentException, FileNotFoundException, IOException

 

  {

    Document doc = new Document(PageSize.A4, 70, 70, 70, 70);

    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    PdfWriter docWriter = PdfWriter.getInstance(doc, bos);

    doc.open();

 

//********************* Code that adds images using URLs **********************/

    // URL url = "" graph;

    // Image img = Image.getInstance(url);

//*************************************************************************************/

 

//*********************** Code that adds a java.awt.Image ***********************/

    Image img = Image.getInstance( (java.awt.Image) graphs, null);

//*************************************************************************************/

 

    img.scalePercent(75, 75);

    img.setAlignment(Image.MIDDLE);

    doc.add(img);

    doc.close();

    FileOutputStream fos = new FileOutputStream(file);

    fos.write(bos.toByteArray());

    fos.close();

    return bos;

  }

 

 

Test results:

=========

 

* Code that adds images using URLs:

 

  Time taken: 251 milliseconds

  Image size: 24KB

 

* Code that adds a java.awt.Image :

 

  Time taken: 282 milliseconds

  Image size: 3KB

 

PLEASE FIND ATTACHED THE RESULTING PDF DOCUMENTS.

 

 

 

 

Attachment: Image.pdf
Description: Image.pdf

Attachment: URL.pdf
Description: URL.pdf

Reply via email to