Hi,
I am facing exception in reading Tiff file using Aspose Document object to create PDF file of it. Originally, I wanted to read Tiff bytes and write them into a PDF. Since I am getting “invalid PDF format” exception in original approach, I tried reading Tiff file which is giving me exception as below
com.aspose.pdf.internal.ms.System.z11: Specified argument was out of the range of valid values.
Code I am trying to use is
ByteArrayOutputStream baos=new ByteArrayOutputStream();
com.aspose.pdf.Document asposeDoc = new com.aspose.pdf.Document();
Page asposePage = asposeDoc.getPages().add();
asposePage.getParagraphs().add(immg);
BufferedImage bufImg = ImageIO.read(new File(“TiffFile.tif”));
ImageIO.write(bufImg, “TIF”, baos);
asposeDoc.save(baos, 40);
Exception occurred: class com.aspose.pdf.internal.ms.System.z11: Specified argument was out of the range of valid values.
Please let me know if further information needed
Thanks
Hello Edward,
I will appreciate if you please share your tiff file. It will help us to understand your scenario and address it accordingly..
We are sorry for the inconvenience.
Best Regards,
Thank you for response Fahaad.
Hello Edward,
Thanks for sharing the sample file.
I have again tested the scenario using Aspose.Pdf for Java 16.12.0 and I am unable to notice any issue when using valid license. For your reference, I have also attached the output generated over my end.
[Java]
// Load source PDF file
ByteArrayOutputStream baos = new ByteArrayOutputStream();
com.aspose.pdf.Document asposeDoc = new com.aspose.pdf.Document();
Page asposePage = asposeDoc.getPages().add();
com.aspose.pdf.Image immg = new com.aspose.pdf.Image();
immg.setFile("c:/pdftest/SampleCorruptPDF.tif");
asposePage.getParagraphs().add(immg);
asposeDoc.save("c:/pdftest/SampleCorruptPDF.pdf");
Hello Nayyar,
Hi. After applying our license properly, I am able to read my TIFF file successfully. However, It is able to read only first page of the file. Below code is able to convert only first page to PDF. Rest of pages are truncated!
Hello Edward,
I will appreciate if you please share your sample project folder here to test in your scenario.
InputStream inputStrm = new ByteArrayInputStream(getBytes);
Sure. Will give project sample in next post. Meanwhile, Let me clarify about your question. “getBytes” is byte[], which we are reading from IBM content manager through Restlet webservice. This byte array is multipage TIFF file stored in IBM content manager. So my brief code for getBytes will be
InputStream inputStrm = new ByteArrayInputStream(getBytes);
// Rest of code
Hello Edward,
Hi,
Hello Edward,
String imageName = “SampleCorruptPDF.tif”;
File file = new File(dirName, imageName);
byte[] bytes = null;
try {
bytes = Files.readAllBytes(file.toPath());
} catch (IOException e) {
e.printStackTrace();
}
InputStream inputStrm = new ByteArrayInputStream(bytes);
com.aspose.pdf.Document asposeDoc = new com.aspose.pdf.Document();
Page asposePage = asposeDoc.getPages().add();
com.aspose.pdf.Image immg = new com.aspose.pdf.Image();
immg.setInNewPage(true); // Added this line to previous code
immg.setImageStream(inputStrm);
asposePage.getParagraphs().add(immg);
asposeDoc.save("/Users/fahadadeel/Downloads/resources/SampleCorruptPDF.pdf");
Thank you very much for response. immg.setImageStream(ImageIO.read(io)) was the main problem for my piece of code. Your solution works as expected with setInNewPage(true) method. Thanks again
Hello Edward,
Thanks for your feedback. It is good to know that suggested code worked for you.
Please keep using our API and feel free to contact us for any question or concern, we will be more than happy to extend our support.
Best Regards,