Free Support Forum - aspose.com

Performance issue with multi-page tiff

Hello,


We are looking for a library can do the Tiff to Pdf conversion. We use ASPOSE.Pdf for .Net with good experiences and we want to use ASPOSE.Pdf for our java application.
We work with multi-page tiff. The tests we did with Aspose.Pdf for Java (11.4.0) gave very good result of conversion, but we had performance problems. Could you help us to improve the performance.Here’s the code we use:
Document doc = new Document();
Page page = doc.getPages().add();
page.getPageInfo().getMargin().setBottom(0);
page.getPageInfo().getMargin().setTop(0);
page.getPageInfo().getMargin().setLeft(0);
page.getPageInfo().getMargin().setRight(0);
page.setCropBox(new com.aspose.pdf.Rectangle(0, 0, 400, 400));
com.aspose.pdf.Image image = new com.aspose.pdf.Image();
OptimizationOptions opt = new OptimizationOptions();
opt.setRemoveUnusedObjects(true);
opt.setLinkDuplcateStreams(true);
doc.optimizeResources(opt);
image.setFile(“C:/tiff/test.tif”);
doc.getPages().get_Item(1).getPageInfo().setLandscape(true);
doc.getPages().get_Item(1).getParagraphs().add(image);
doc.save(“C://tiff/Aspose.pdf”);

We also attach a TIFF file generated by our application.
Thank you for your assistance

Hi Stanislava,


Thanks for contacting support.

I have tested the scenario and have managed to reproduce that TIFF to PDF conversion process takes around 2 minutes. For the sake of correction, I have logged it as PDFNEWJAVA-35786 in our issue tracking system. We will further look into the details of this problem and will keep you posted on the status of correction. Please be patient and spare us little time. We are sorry for this inconvenience.

Hi,



Do you have any news regarding this issue? Is there a way for us to access your issue tracking system to follow up on it?

Thanks,
Vincent

Hi Vincent,


Thanks for your inquriy. I am afraid the issue is still not resolved and it is pending for investigation as product team is busy in resolving other issues in the queue. We will notify you as soon as it is resolved.

Furthermore, our issue tracking system(JIRA) is our internal system and I am afraid you can not access it. However you may check the status with issue id in left column of the thread or you can ask us for the updates, we will be glad to update you the issue resolution progress.

In reference to performance issue, if you do not have priority to retain image color then you can use setBlackWhite() property. It will improve the performance in terms of processing time and resultant file size as well.

Document doc = new Document();<o:p></o:p>

Page page = doc.getPages().add();

page.getPageInfo().getMargin().setBottom(0);

page.getPageInfo().getMargin().setTop(0);

page.getPageInfo().getMargin().setLeft(0);

page.getPageInfo().getMargin().setRight(0);

page.setCropBox(new com.aspose.pdf.Rectangle(0, 0, 400, 400));

com.aspose.pdf.Image image = new com.aspose.pdf.Image();

image.setFile("test.tif");

image.setBlackWhite(true);

doc.getPages().get_Item(1).getPageInfo().setLandscape(true);

doc.getPages().get_Item(1).getParagraphs().add(image);

doc.save("Converted_Aspose.pdf");


We are sorry for the inconvenience caused.

Best Regards,
Hi,

Thank you for your answer. Unfortunately, we havn't had an improvement in performance by adding .setBackWhite(true). So, we decided to adopt another way : we convert each Tiff frame to JPG in a first step and then we use Aspose to create the PDF in a second step. The execution time is much faster than the proposed solution. The problem is that the package PDF doesn't exist in the latest versions of Aspose.Pdf. Could you tell us how to remplace the classes Pdf and Section. Here is our code :

ImageInputStream iis = ImageIO.createImageInputStream(new FileInputStream("test.tiff"));
Iterator readers = ImageIO.getImageReaders(iis);
ImageReader ir = readers.next();
ir.setInput(iis);
int frameCount = ir.getNumImages(true);

Pdf pdf1 = new Pdf();
Section sec1 = pdf1.getSections().add();

// iterate through each TIFF frame
for (int i = 0; i <frameCount; ++i)
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(ir.read(i), "jpg", baos);
baos.flush();

Image img1 = new Image(sec1);
sec1.getParagraphs().add(img1);
img1.setImageStream(new ByteArrayInputStream(baos.toByteArray()));
img1.setImageFileType(com.aspose.pdf.ImageFileType.Jpeg);
}

pdf1.save("aspose.pdf");
iis.close();

Thank you for your help,

Stanislava

Hi Stanislava,


Thanks for your feedback. In reference to suggestion setBlackWhite() property of com.aspose.pdf.Image, it should increase the performance. We will appreciate it if you please share your sample code and environment details, so we will investigate it further.

In reference to your above code. you are using old generator. It is recommended to use new generator, it is more improved and efficient. It can create a new PDF from scratch and manipulate existing PDF documents as well. In new generator, Document and Page objects are replacement of Pdf and Section objects of old generator. Please find updated code here. Hopefully it will help you to accomplish the task.

Document pdf1 = new Document();<o:p></o:p>

com.aspose.pdf.Page sec1 = pdf1.getPages().add();

// iterate through each TIFF frame

for (int i = 0; i <frameCount; ++i)

{

ByteArrayOutputStream baos = new ByteArrayOutputStream();

ImageIO.write(ir.read(i), "jpg", baos);

baos.flush();

com.aspose.pdf.Image img1 = new com.aspose.pdf.Image();

sec1.getParagraphs().add(img1);

img1.setImageStream(new ByteArrayInputStream(baos.toByteArray()));

//img1.setImageFileType(com.aspose.pdf.ImageFileType.Jpeg);

}

pdf1.save("aspose.pdf");

iis.close();


Best Regards,

Hi,

Thank you for your answer. I applied the new generator but the performances are worse than with the old one : 10 sec against 3 sec for a file of 100 pages (I join the file too this message). Our environment is: Windows 10, Eclipse, WebApp.

Despite all, this solution has better performance than that recommanded by Aspose. Using setBlackWhite() property of com.aspose.pdf.Image we have the following error when opening the generated pdf whit AcrobatReader: "Insufficient data for an image".

there is our sample code:

com.aspose.pdf.Document doc = new Document();

com.aspose.pdf.Page page = doc.getPages().add();

page.getPageInfo().getMargin().setBottom(0);

page.getPageInfo().getMargin().setTop(0);

page.getPageInfo().getMargin().setLeft(0);

page.getPageInfo().getMargin().setRight(0);

page.setCropBox(new com.aspose.pdf.Rectangle(0, 0, 400, 400));

com.aspose.pdf.Image image = new com.aspose.pdf.Image();

image.setFile(fromFile.getAbsolutePath());

image.setBlackWhite(true);

doc.getPages().get_Item(1).getPageInfo().setLandscape(true);

doc.getPages().get_Item(1).getParagraphs().add(image);

doc.save(toFile.getAbsolutePath());


Thanks a lot for your help!
Best regards,


Hi Stanislava,

Thanks for your inquiry. I have converted your shared PDF to PNG using Aspose.Pdf for Java 16.10.0 and unable to notice any exception. It took almost 36 seconds for processing. I am using -Xmx4G -Xms4G JVM heap parameters.

Please note Aspose.Pdf processes the files in memory instead disk, so performance depends upon the file size/contents and system resources. So it is recommended to increase heap memory size for processing big files. Please try latest version of Aspose.Pdf for Java, increase JVM heap settings to -Xmx4G -Xms4G, test the scenario and share the results.

Furthermore, in reference to your approach of iterating through the tiff frames, you may use Aspose.Imaging with collaboration of Aspose.Pdf as following as well.

Document pdf = new Document();

com.aspose.imaging.fileformats.tiff.TiffImage tiff = (com.aspose.imaging.fileformats.tiff.TiffImage)com.aspose.imaging.Image.load("D:\\Downloads\\TIFF_100.tif") ;

for (TiffFrame f : tiff.getFrames())

{

com.aspose.pdf.Page page = pdf.getPages().add();

com.aspose.pdf.Image img = new com.aspose.pdf.Image();

page.getParagraphs().add(img);

page.getPageInfo().getMargin().setBottom(0);

page.getPageInfo().getMargin().setTop(0);

page.getPageInfo().getMargin().setLeft(0);

page.getPageInfo().getMargin().setRight(0);

page.setCropBox(new com.aspose.pdf.Rectangle(0, 0, 400, 400));

ByteArrayOutputStream output = new ByteArrayOutputStream();

{

f.save(output, new JpegOptions());

img.setImageStream(new ByteArrayInputStream(output.toByteArray()));

}

}

pdf.save(myDir + "test11.pdf");


Best Regards,
Hi,

Thank you for your answer. By increasing the JVM heap settings we have improved some performance : using Aspose.PDF for Java 16.10.0 we have 40 sec (agains 1 min) for processing the 200 pages file. Despite this improvement, the performance are worse than using the conversion Tiff frames to Jpg (Java conversion) and then to Pdf (Aspose.Pdf) : the conversion with this method is 18 sec with Aspose.Pdf 16.10.0 and 6,5 with Aspose.Pdf 11.9. Using Aspose.Imaging in this case doesn't imrove the performance because the conversion of tiff frames to images is faster with Java.

We tested your example in a separate project (not in a WebApp). But when we added the property setBlackWhite() of com.aspose.pdf.Image we had the same message ("Insufficient data for an image". ) when opening the generated pdf file with AcrobatReader. No exception in the log.

Best regards,

Stanislava




Hi Stanislava,

spopovIris:

Thank you for your answer. By increasing the JVM heap settings we have improved some performance : using Aspose.PDF for Java 16.10.0 we have 40 sec (agains 1 min) for processing the 200 pages file. Despite this improvement, the performance are worse than using the conversion Tiff frames to Jpg (Java conversion) and then to Pdf (Aspose.Pdf) : the conversion with this method is 18 sec with Aspose.Pdf 16.10.0 and 6,5 with Aspose.Pdf 11.9. Using Aspose.Imaging in this case doesn't imrove the performance because the conversion of tiff frames to images is faster with Java.


Thanks for your feedback. It is good to know that increase JVM heap setting helped to improve the performance. I have tried to test Tiff frames to to JPG(Java conversion) and then to PDF using Aspose.Pdf performance difference with different versions but I am afraid I am getting an JAI exception even adding JAI in classpath, however I have logged an investigation ticket PDFJAVA-36328 in out issue tracking system for further investigation.

spopovIris:

We tested your example in a separate project (not in a WebApp). But when we added the property setBlackWhite() of com.aspose.pdf.Image we had the same message ("Insufficient data for an image". ) when opening the generated pdf file with AcrobatReader. No exception in the log.


I am afraid I am unable to notice this issue at my end, Please share your environment details and confirm whether you have increased JVM heap in that specific environment. We will try to replicate the issue with these details.

We are sorry for the inconvenience.

Best Regards,