Hi,
We have a use case where we have to convert a bunch of documents per request to pdf so our users can view them on the browser without downloading them. In a user session we can have about 5 to 40 documents, and these files include word, images, tiffs (scanned docs), html, pdfs etc.
The other file formats take a reasonable amount of time to convert for our use case (500 milliseconds to 2 secods), the issue is tiff files, they take about 15 seconds to about 50 seconds (or even more for multipage tiffs). This is not ideal for our use case, and they also cause a huge memory strain on our server such that we have to restart our porduction server for about 4 times a day.
For this, We are using aspose-imaging-20.11 for this, running in tomcat8, java jdk8. I have attached a tiff file that takes about 15 seconds to convert as well as the code we are using for the conversion. Could you please help.
Please note we are doing a lot of resource clean up to try and deal with the memory issues.CurrentDocument_02122020_125745.zip (5.0 MB)
final Document doc = new Document();
ByteArrayOutputStream output = null;
InputStream imageInputStream = null;
Page page;
try (InputStream inputStream = new ByteArrayInputStream(input); com.aspose.imaging.Image imagingImage = com.aspose.imaging.Image
.load(inputStream)) {
page = doc.getPages().add();
page.getPageInfo().setMargin(new MarginInfo());
page.setPageSize(imagingImage.getWidth(), imagingImage.getHeight());
final Image pdfImage = new Image();
imageInputStream = new ByteArrayInputStream(input);
pdfImage.setImageStream(imageInputStream);
page.getParagraphs().add(pdfImage);
output = new ByteArrayOutputStream();
doc.save(output, SaveFormat.Pdf);
} catch (ImageLoadException | IOException e) {
return new byte[]{};
} finally {
if (Objects.nonNull(imageInputStream)) {
try {
imageInputStream.close();
} catch (IOException e) {
//logger.error(e.getMessage(), e);
}
}
if (Objects.nonNull(output)) {
try {
output.close();
} catch (IOException e) {
//logger.error(e.getMessage(), e);
}
}
doc.dispose();
doc.close();
}