Memory Error

Memory Error

Forum member · Nov 16, 2005
Hi, My requirement is to write a PDF document with TIFF images, one in each page. These TIFF images are dynamically taken from a location and there can be huge files, as many as 2000 TIFF files. When i create a PDF document using them as: Document document = new Document(); for (loop through the TIFF files) { TiffFile file = new TiffFile(fileLink); document.append(file.getDocument()); } document.draw(outStream); I get an error: FileNotFoundException ( Too many Open Files). I think PDF generator loads all files into memory and then writes all of them at a time to a out stream. Is there a way that i can write the TIFF images one at a time to the file or stream and close that file?? When i try giving "file.close()" after document.append(), it throws an error too. Please help as this is effecting my PROD application and failing PDF generations of big files. Regards, Ravi.

Re: Memory Error

Support · Nov 16, 2005
Hello Ravi, The workaround is to load the Tiff images into the byte array and then pass the byte array to the TiffFile constructor. Here is the code snippet: Document document = new Document(); for (loop through the TIFF files) { File file = new File( fileLink ); FileInputStream fin = new FileInputStream(file); byte[] buffer = new byte[(int)file.length()]; fin.read(buffer); fin.close(); TiffFile tiff = new TiffFile(buffer); document.append(tiff.getDocument()); } document.draw(outStream); Thanks, ceTe Software Support Team.

Re: Memory Error

Forum member · Nov 16, 2005
Thanks for the reply. Is there any way to create the PDF document without loading all the images into memory? My Images will be of very huge size and that will hung up. Also, if my list has multiple file types ( TIFF, JPG, GIF mixed together), how do i handle that scenario? Regards, Ravi.

Re: Memory Error

Support · Nov 16, 2005
Hello Ravi, There is no way you can create the PDF document without loading the images in memory. Yes, you can handle different image file types without any problem but you will have to know the image type before hand. For any images other than the Tiff's you will have to use the following method to add them to the document. // For non TIFF images Page page = ImageData.getImage(fileLink).getPage(); document.getPages().add(page); Thanks, ceTe Software Support Team.