Converting XLSX Files To PDF With Embedded TIFFs

Hi,


When using Cells 7.5.0 to convert an XLSX file to a PDF with embedded TIFFs, I am getting the following exception…

Caused by: com.aspose.cells.CellsException: Unknown image format:invalid image stream or image format is not supported.
at com.aspose.cells.cm.a(Unknown Source)
at com.aspose.cells.lz.a(Unknown Source)
at com.aspose.cells.zj.a(Unknown Source)
at com.aspose.cells.zj.c(Unknown Source)
at com.aspose.cells.zj.a(Unknown Source)
at com.aspose.cells.zy.j(Unknown Source)
at com.aspose.cells.zy.b(Unknown Source)
at com.aspose.cells.zy.u(Unknown Source)
at com.aspose.cells.zy.a(Unknown Source)
at com.aspose.cells.zx.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.(Unknown Source)

However, the conversion works fine when converting from XSL to PDF with the same library. Attached is an example of a failing XLSX file.

Thanks,

Tom McLean

Hi,

Thanks for your posting and using Aspose.Cells for Java.

We have checked your issue with the latest version and it works fine. Please download and use the latest version: Aspose.Cells for Java 7.5.2.

We have attached the output pdf file for your reference.

I just tried this with Cells 7.5.2, JDK 1.7.0_21 and JDK 1.6.0_35 on Windows 7 with the same results. The offending line of code is…


com.aspose.cells.Workbook excelDoc = new com.aspose.cells.Workbook( “/Users/Tom McLean/Desktop/TIFF Test/tiff_test.xlsx” );

…and the exception is…

Exception in thread “main” com.aspose.cells.CellsException: Unknown image format:invalid image stream or image format is not supported.
at com.aspose.cells.cm.a(Unknown Source)
at com.aspose.cells.mc.a(Unknown Source)
at com.aspose.cells.zo.a(Unknown Source)
at com.aspose.cells.zo.c(Unknown Source)
at com.aspose.cells.zo.a(Unknown Source)
at com.aspose.cells.aad.j(Unknown Source)
at com.aspose.cells.aad.b(Unknown Source)
at com.aspose.cells.aad.u(Unknown Source)
at com.aspose.cells.aad.a(Unknown Source)
at com.aspose.cells.aac.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.(Unknown Source)
at Main.main(Main.java:7)

Also, this was built from a blank Eclipse project and the only library included was aspose-cells-7.5.2.jar

Hi,

Thanks for your posting and using Aspose.Cells for Java.

Please also add the following jar files in your class path and build the project. You can find them in the JDK 1.6 folder of the version which you downloaded.

  • bcprov-jdk16-146.jar
  • dom4j-1.6.1.jar

Please also add the JAI library which is needed for tiff images. You can download JAI library from internet. These are the JAI library JAR files.

  • jai_core.jar
  • jai_imageio-1.1-alpha.jar

This seems to work for a command line application, but fails in the same manner when called from within a servlet.


Example:

package com.feith.aspose.test;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class AsposeTestServlet extends HttpServlet
{
@Override
protected void doGet( HttpServletRequest req, HttpServletResponse resp ) throws ServletException, IOException
{
try
{
com.aspose.cells.Workbook excelDoc = new com.aspose.cells.Workbook( “/Users/Tom McLean/Desktop/TIFF Test/tiff_test.xlsx” );
com.aspose.cells.WorksheetCollection workSheets = excelDoc.getWorksheets();
for( int i = 0; i < workSheets.getCount(); i++ )
{
workSheets.get( i ).getPageSetup().setFitToPagesWide( 1 );
}
com.aspose.cells.PdfSaveOptions xlsxOpts = new com.aspose.cells.PdfSaveOptions();
xlsxOpts.setCompliance( com.aspose.cells.PdfCompliance.NONE );
xlsxOpts.setEmbedStandardWindowsFonts( true );
}
catch( Exception e )
{
e.printStackTrace();
}
super.doGet(req, resp);
}
}

…when called produces…

com.aspose.cells.CellsException: Unknown image format:invalid image stream or image format is not supported.
at com.aspose.cells.cm.a(Unknown Source)
at com.aspose.cells.mc.a(Unknown Source)
at com.aspose.cells.zo.a(Unknown Source)
at com.aspose.cells.zo.c(Unknown Source)
at com.aspose.cells.zo.a(Unknown Source)
at com.aspose.cells.aad.j(Unknown Source)
at com.aspose.cells.aad.b(Unknown Source)
at com.aspose.cells.aad.u(Unknown Source)
at com.aspose.cells.aad.a(Unknown Source)
at com.aspose.cells.aac.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.(Unknown Source)
at com.feith.aspose.test.AsposeTestServlet.doGet(AsposeTestServlet.java:19)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)

Hi,

Thanks for your posting and using Aspose.Cells for Java.

Please add the JAI library in your class path. This error occurs if the JAI library is missing. Once, you will add it in your class path, it will work fine.

  • jai_core.jar
  • jai_imageio-1.1-alpha.jar

They are in the classpath. The WEB-INF/lib directory contains the following JAR files.


aspose-cells-7.5.2.jar
bcprov-jdk16-146.jar
dom4j-1.6.1.jar
jai_imageio-1.1-alpha.jar
jai-core-1.1.3.jar

These classpath entries are identical to the command line application that I put together that works.

In fact I added the line

System.out.println( ImageIO.class.getName() );

To the beginning of the doGet() function in the servlet. The result was

javax.imageio.ImageIO
com.aspose.cells.CellsException: Unknown image format:invalid image stream or image format is not supported.
at com.aspose.cells.cm.a(Unknown Source)
at com.aspose.cells.mc.a(Unknown Source)
at com.aspose.cells.zo.a(Unknown Source)
at com.aspose.cells.zo.c(Unknown Source)
at com.aspose.cells.zo.a(Unknown Source)
at com.aspose.cells.aad.j(Unknown Source)
at com.aspose.cells.aad.b(Unknown Source)
at com.aspose.cells.aad.u(Unknown Source)
at com.aspose.cells.aad.a(Unknown Source)
at com.aspose.cells.aac.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.(Unknown Source)
at com.feith.aspose.test.AsposeTestServlet.doGet(AsposeTestServlet.java:22)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)

Notice it was able to find and obtain a Class reference to the ImageIO library and print its name. This sounds like an issue in the Slides library referencing a classloader that has no knowledge of the ImageIO libraries.

Hi,

Thanks for your posting and using Aspose.Cells for Java.

It is strange, you are still getting this exception after adding all the JAR files. We have logged this issue in our database for investigation. We will look into it and update you. Once, there is some update for you, we will let you know asap.

This issue has been logged as CELLSJAVA-40599.

Hi,

Well, for this issue, we have tested it with your given servlet code but could not find the issue. If we did not add jai-imageio.jar and jai-core.jar into the application’s lib(application/WEB-INF/lib), we will get the exception “com.aspose.cells.CellsException: Unknown image format:invalid image stream or image format is not supported.” When we add those two jars into the lib, the workbook can be opened fine. To check whether the jai libraries take effect, please use ImageIO.getReaderFormatNames() in the servlet to check the supported image formats. If the libraries take effect, tiff should be in the returned array. So we think maybe it is an issue of the configuration of your web application.

Thank you.

Thank you Amjad, that pointed me in the right direction. It turns out due to some strange classloading issue, the jai-core library was not detecting the jai-imageio library as a plugin. A manual call to ImageIO.scanForPlugins() resolved the issue.

Hi,

Thanks for your posting and using Aspose.Cells.

It is good to know that your issue is resolved now. If you encounter any other issue, please feel free to post, we will be glad to help you further.