We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Empty PDF produced with Aspose.Pdf 9.0

HI,


I’m using the following code and image to create a PDF from a TIFF file.
In the result I get an empty (0kb) file. Please help.


File file = new File(“path.tiff”);
File pdfFile = File.createTempFile(“renderer_”, “.pdf”);
//Instantiate Pdf instance by calling its empty constructor
Pdf pdf1 = new Pdf();
//Create a new section in the Pdf object
Section sec1 = pdf1.getSections().add();
//Create an image object in the section
Image image = new aspose.pdf.Image(sec1);
//Add image object into the Paragraphs collection of the section
sec1.getParagraphs().add(image);
//Set the ImageStream information
image.getImageInfo().setSystemImage(ImageIO.read(file));
// set the value that all frames of tiff image need be added into PDF document
image.getImageInfo().setTiffFrame(-1);
//Save the pdf document
pdf1.save(pdfFile.getAbsolutePath());


It works fine for other image formats with the code provided on the sample page below:
http://www.aspose.com/docs/display/pdfjava/How+to+Convert+an+Image+to+PDF
Thanks,
Mariusz

I tried and it’s the same with v9.1. I don’t have JAI library in the classpath. It used to work with pre-9 version with pdf-kit as a separate library.

Please help!

Thanks,
Mariusz

Hi Mariusz,


Thanks for your inquiry. We have managed to replicate the issue and logged it as PDFNEWJAVA-34246 in our issue tracking system for further investigation and resolution. We will keep you updated about the issue resolution progress via this forum thread.

However, as a workaround you can use SetFile() method to assign image to Image object. Hopefully it will help you to accomplish the task.

Pdf pdf = new Pdf();
Section sec = pdf.getSections().add();
aspose.pdf.Image img = new aspose.pdf.Image(sec);
sec.getParagraphs().add(img);
img.getImageInfo().setImageFileType(ImageFileType.Tiff);
// img1.getImageInfo().setIsBlackWhite(true);
img.getImageInfo().setFile(myDir+“tiff.tif”);
img.getImageInfo().setTiffFrame(-1);
img.setImageScale(0.95F);
pdf.save(myDir+“TIFFConversion_image_toPDF2.pdf”);

We are sorry for the inconvenience caused.

Best Regards,

Workaround works. Thank you.


Regards,
Mariusz

Hi Mariusz,


Thanks for your feedback. It is good to know that the workaround help you to accomplish the task. However we will keep you updated about the original issue resolution progress via this forum thread.

Best Regards,

Just one question - what’s the point in exposing the same functionality in two different ways? Is the original code sample better/faster than the workaround? Which code should I use once it’s fixed?


Thanks for all your help!
Mariusz

Hi Mariusz,


Thanks for your inquiry. There is no difference in performance in both Methods but argument type. You may use either of these it depends upon your choice or need. As currently getSystemImage() method is not working so we have logged an issue in our issue tracking system for the purpose. We will update you as soon as it is resolved.


getFile(String image)

Gets a string that indicates the image file name and its path or url of a web image.

getSystemImage( com.aspose.ms.System.Drawing.Image image)

Gets a system System.Drawing.Image object which is used to create a Aspose Aspose.Pdf.Image object.

We are sorry for the inconvenience caused.

Best Regards,