Free Support Forum - aspose.com

TIF to PDF (aspose-pdf-3.2.0-java)

Hey Aspose Team,

first thank you for your quick and helpful replies.

There are some things and unfortunately problems I'm running into. The code snippet I have looks as follows:

Pdf pdf = new Pdf();
Section section = pdf.getSections().add();

BufferedImage bImage = ImageIO.read(new FileInputStream(source));

Image image = new Image(section);
ImageInfo imageInfo = image.getImageInfo();
imageInfo.setFile(source);
imageInfo.setImageFileType(ImageFileType.Tiff);

section.setIsLandscape(bImage.getWidth() > bImage.getHeight());
section.getParagraphs().add(image);
pdf.save(target);

Note 1: I can't replace "imageInfo.setFile(source);" with "imageInfo.setSysImageStream(bImage);" because this leads to a null pointer exception:

java.lang.NullPointerException
at aspose.pdf.figure.Acc.a(SourceFile:52)
at aspose.pdf.figure.Abg.a(SourceFile:53)
at aspose.pdf.figure.Abi.a(SourceFile:160)
at aspose.pdf.figure.Abi.a(SourceFile:182)
at aspose.pdf.figure.Aba.a(SourceFile:156)
at aspose.pdf.xml.Abi.a(SourceFile:212)
at aspose.pdf.xml.Abi.a(SourceFile:618)
at aspose.pdf.xml.Abj.a(SourceFile:578)
at aspose.pdf.xml.Acd.a(SourceFile:804)
at aspose.pdf.xml.Aar.a(SourceFile:104)
at aspose.pdf.xml.Aba.a(SourceFile:113)
at aspose.pdf.Pdf.save(SourceFile:929)

Note 2: Creating a tif image using paint in Windows (windows 7), can not be opened by Aspose, the file is attached.

java.lang.RuntimeException: Couldn't open image file: \input.tif
at aspose.pdf.figure.Acb.a(SourceFile:252)
at aspose.pdf.figure.Abi.a(SourceFile:90)
at aspose.pdf.figure.Aba.a(SourceFile:152)
at aspose.pdf.figure.Aba.a(SourceFile:99)
at aspose.pdf.xml.Abi.a(SourceFile:208)
at aspose.pdf.xml.Abi.a(SourceFile:618)
at aspose.pdf.xml.Abj.a(SourceFile:578)
at aspose.pdf.xml.Acd.a(SourceFile:804)
at aspose.pdf.xml.Aar.a(SourceFile:104)
at aspose.pdf.xml.Aba.a(SourceFile:113)
at aspose.pdf.Pdf.save(SourceFile:929)

Note 3: I have image files that do get converted (at least it looks like it), but when I open the pdf file Adobe Reader shows an error popup with "Insufficient data for an image." The pdf in the background is blank. The file is attached.

Note 4: I'm having a TIF that contains several "images" inside. Is there a way to iterate over them?

Note 5: When running those JAI jar's (clibwrapper_jiio.jar, jai_codec.jar, jai_core.jar, jai_imageio.jar, mlibwrapper_jai.jar) in an application server... those need to be endorsed with vm argument -Djava.endorsed.dirs=/lib/endorsed

Note 5: I want to mention that there are TIF's where the conversion works fine :)

I want to thank you in advance for your help.

Kind regards

Peter

cyberstorm:
Note 1: I can’t replace “imageInfo.setFile(source);” with “imageInfo.setSysImageStream(bImage);” because this leads to a null pointer exception:

java.lang.NullPointerException
at aspose.pdf.figure.Acc.a(SourceFile:52)
at aspose.pdf.figure.Abg.a(SourceFile:53)
at aspose.pdf.figure.Abi.a(SourceFile:160)
at aspose.pdf.figure.Abi.a(SourceFile:182)
at aspose.pdf.figure.Aba.a(SourceFile:156)
at aspose.pdf.xml.Abi.a(SourceFile:212)
at aspose.pdf.xml.Abi.a(SourceFile:618)
at aspose.pdf.xml.Abj.a(SourceFile:578)
at aspose.pdf.xml.Acd.a(SourceFile:804)
at aspose.pdf.xml.Aar.a(SourceFile:104)
at aspose.pdf.xml.Aba.a(SourceFile:113)
at aspose.pdf.Pdf.save(SourceFile:929)

Hi Peter,

Thanks for using our products.

I have tested this scenario and have managed to reproduce the same problem. For the sake of correction, I have logged this problem as PDFJAVA-33158 in our issue tracking system.

cyberstorm:
Note 2: Creating a tif image using paint in Windows (windows 7), can not be opened by Aspose, the file is attached.

java.lang.RuntimeException: Couldn't open image file: \input.tif
at aspose.pdf.figure.Acb.a(SourceFile:252)
at aspose.pdf.figure.Abi.a(SourceFile:90)
at aspose.pdf.figure.Aba.a(SourceFile:152)
at aspose.pdf.figure.Aba.a(SourceFile:99)
at aspose.pdf.xml.Abi.a(SourceFile:208)
at aspose.pdf.xml.Abi.a(SourceFile:618)
at aspose.pdf.xml.Abj.a(SourceFile:578)
at aspose.pdf.xml.Acd.a(SourceFile:804)
at aspose.pdf.xml.Aar.a(SourceFile:104)
at aspose.pdf.xml.Aba.a(SourceFile:113)
at aspose.pdf.Pdf.save(SourceFile:929)

We will consider investigating this issue under PDFJAVA-33158.

cyberstorm:
Note 3: I have image files that do get converted (at least it looks like it), but when I open the pdf file Adobe Reader shows an error popup with "Insufficient data for an image." The pdf in the background is blank. The file is attached.

I have separately logged this problem as PDFJAVA-33159 in our issue tracking system. We will further look into the details of these problems and will keep you updated on the status of correction. Please be patient and spare us little time.

cyberstorm:
Note 4: I'm having a TIF that contains several "images" inside. Is there a way to iterate over them?

Aspose.Pdf for Java supports the capability to convert various file formats including Image files into PDF format but I am afraid it does not support the feature to iterate through images inside TIFF file. However as a workaround, once the TIFF image is converted into PDF format, you may consider using Aspose.Pdf.Kit for Java which supports the capability to manipulate existing Pdf documents. It also supports the feature to extract images from PDF file. So as a solution, you may consider using the following code snippet to get the image count inside PDF document. In case you encounter any issue or you have any further query, please feel free to contact.

[Java]

// Instantiate PdfFileInfo object

com.aspose.pdf.kit.PdfFileInfo pdfFileInfo = new com.aspose.pdf.kit.PdfFileInfo("D:/pdftest/DOC001fromscanner.PDF");

// get the count of pags inside pdf

int numOfPagesInPdf = pdfFileInfo.getNumberofPages();

// display page count

System.out.println("Page Count: "+numOfPagesInPdf);

// instantiate PdfExtractor object

PdfExtractor extractor = new PdfExtractor();

//Bind the input PDF document to extractor

extractor.bindPdf("D:/pdftest/Test.pdf");

// set the start page

extractor.setStartPage(1);

// end page

extractor.setEndPage(numOfPagesInPdf);

//Extract images from the input PDF document

extractor.extractImage();

String suffix = ".jpg";

int imageCount = 1;

while (extractor.hasNextImage()) {

extractor.getNextImage("D:/pdftest/DOC001fromscanner-Image"+ imageCount + suffix);

System.out.println("imageCount: "+imageCount);

imageCount++;

}


For further details, please have a look over

cyberstorm:
Note 5: When running those JAI jar's (clibwrapper_jiio.jar, jai_codec.jar, jai_core.jar, jai_imageio.jar, mlibwrapper_jai.jar) in an application server... those need to be endorsed with vm argument -Djava.endorsed.dirs=/lib/endorsed

Can you please share what problems you are facing, in case the arguments are missing.

We are sorry for your inconvenience.

Hey Nayyer,

many thanks for you quick response time, tracking issues and helpful message.

codewarior:
Can you please share what problems you are facing, in case the arguments are missing.

I'm running Aspose in an Application Server and the standard Java Runtime does not include TIF support/reader for ImageIO. So I have to get JAI (Java Advanced Imaging and Java Advanced Imaging I/O Tools) components and include them in my JVM as endorsed jar's within the Application Server, just in classpath does not work.

Without JAI in JRE 6, ImageIO does only support: jpg, gif, bmp, jpeg, png, wbmp

With JAI: jpg, gif, bmp, jpeg2000, raw, jpeg, png, wbmp, pnm, tif, tiff

Have a nice day.

Kind regards

Peter

Hi Peter,

Thanks for sharing the details.

I am working over this scenario and will get back to you soon. Please be patient and spare us little time. We are sorry for the delay and inconvenience.

cyberstorm:
I'm running Aspose in an Application Server and the standard Java Runtime does not include TIF support/reader for ImageIO. So I have to get JAI (Java Advanced Imaging and Java Advanced Imaging I/O Tools) components and include them in my JVM as endorsed jar's within the Application Server, just in classpath does not work.

Without JAI in JRE 6, ImageIO does only support: jpg, gif, bmp, jpeg, png, wbmp

With JAI: jpg, gif, bmp, jpeg2000, raw, jpeg, png, wbmp, pnm, tif, tiff

Hi Peter,

I have gone through the your requirement and I think you may consider following the specified below. Get JAI library from oracle site, as JAI comes in Setup script either in .sh, .exe etc form, install it over your system and it will set JAI to java system catalog. This will save you from setting JAI path against JRE. Once you have installed JAI, you may consider executing the following code snippet to test if its properly installed and JAI can be accessed by your application.

[Java]

private static void printlist(String names[],String title) {

System.out.println(title);

for (int i = 0, n = names.length; i < n; i++) {

System.out.println("\t" + names[i]);

}

}

public void testJAI() throws Exception {

ImageIO.scanForPlugins();

String readerNames[] = ImageIO.getReaderFormatNames();

printlist(readerNames, "Reader names:");

}


If the code returns jpeg2000 and TIFF, installation is successful. I have used jai_imageio-1_1-lib-windows-i586-jre.exe in my environment. For any related query, please feel free to contact.

Hey Nayyer,

thank you for your reply.

I missed to mention that I'm not allowed to modify the Application Servers JRE. There are many applications deployed and its a clustered Websphere 7 environment. Setting the endorsed path in Websphere's "Generic JVM arguments" property works without modifying the IBM JRE.

Kind regards

Peter

Hi Peter,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for the feedback.

We will further look into your query and get back to you soon.

Sorry for the inconvenience,

Hi Peter,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for being patient.

Our development team is working on your reported issues and your reported issue PDFJAVA-33158 and PDFJAVA-33159 are fixed and will be included in our upcoming release. However, our development team needs further investigation and testing of your issues as per the details shared by you regarding your environment. Once we have any feedback from the development team, we will update you via this forum thread.

Sorry for the inconvenience.

The issues you have found earlier (filed as PDFJAVA-33158;PDFJAVA-33159) have been fixed in Aspose.Pdf for Java 3.3.0.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.