Hello,
Hi Stanislava,
Hi,
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();
Page page = doc.getPages().add();
// Set margins to 0
page.getPageInfo().getMargin().setBottom(0);
page.getPageInfo().getMargin().setTop(0);
page.getPageInfo().getMargin().setLeft(0);
page.getPageInfo().getMargin().setRight(0);
// Set the crop box size
page.setCropBox(new com.aspose.pdf.Rectangle(0, 0, 400, 400));
// Load an image and set its properties
com.aspose.pdf.Image image = new com.aspose.pdf.Image();
image.setFile("test.tif");
image.setBlackWhite(true);
// Set the page to landscape
doc.getPages().get_Item(1).getPageInfo().setLandscape(true);
// Add the image to the page
doc.getPages().get_Item(1).getParagraphs().add(image);
// Save the document
doc.save("Converted_Aspose.pdf");
We are sorry for the inconvenience caused.
Best Regards,
Iterator readers = ImageIO.getImageReaders(iis);
ImageReader ir = readers.next();
ir.setInput(iis);
Section sec1 = pdf1.getSections().add();
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();
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();
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()));
// Optional: Set the image file type as JPEG
// img1.setImageFileType(com.aspose.pdf.ImageFileType.Jpeg);
}
pdf1.save("aspose.pdf");
iis.close();
Best Regards,
com.aspose.pdf.Page page = doc.getPages().add();
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);
// Set margins
page.getPageInfo().getMargin().setBottom(0);
page.getPageInfo().getMargin().setTop(0);
page.getPageInfo().getMargin().setLeft(0);
page.getPageInfo().getMargin().setRight(0);
// Set crop box
page.setCropBox(new com.aspose.pdf.Rectangle(0, 0, 400, 400));
// Convert TIFF frame to JPEG and add to PDF
ByteArrayOutputStream output = new ByteArrayOutputStream();
f.save(output, new JpegOptions());
img.setImageStream(new ByteArrayInputStream(output.toByteArray()));
}
pdf.save(myDir + "test11.pdf");
Best Regards,
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.
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.