Xls and xml conversion to PDF using Aspose Cells

Hi,

Can you please help me with the right way to convert xsl and xml files to PDF.

I have used the following approach but it doesnot work.

For xml:

Pdf pdf = new Pdf();

pdf = Pdf.bindXML(new FileInputStream(fileName));

//Filename is the name of the xsl file

//Create the PDF document by calling its save method

pdf.save(new FileOutputStream(fileName.substring(0,

fileName.lastIndexOf("\\"))

+ "\\" + fileName.substring(fileName.lastIndexOf("\\")+1,fileName.lastIndexOf('.')) + ".pdf"));

and for xsl: Dont know what to do...


This message was posted using Page2Forum from Aspose.Cells for Java - Documentation

Hi,

Please see the following documentation link for XLS2PDF conversion. It contains the latest code and details for XLS2PDF conversion which you may try as per your scenario.

http://www.aspose.com/documentation/java-components/aspose.cells-for-java/converting-to-pdf-files.html

Thank You & Best Regards,

Hi,

Thanks for your response. I tried the same. But i get the following exception.

com.aspose.pdf.exception.AsposeBaseException: null

at com.aspose.pdf.elements.Section.a(Unknown Source)

at com.aspose.pdf.elements.Pdf.if(Unknown Source)

at com.aspose.pdf.elements.Pdf.a(Unknown Source)

at com.aspose.pdf.elements.Pdf.save(Unknown Source)

at com.unica.ConvertXLSToPDF.convert(ConvertXLSToPDF.java:33)

at com.unica.SampleController.main(SampleController.java:21)

The conversion code is as follows:

public boolean convert(String fileName){

//Instantiate the Workbook object

Workbook workbook = new Workbook();

try {

workbook.open(fileName);

workbook.save("C:\\Aspose\\Aspose_Input\\sheet.xml", FileFormatType.ASPOSE_PDF);

Pdf pdf = new Pdf();

pdf = Pdf.bindXML(new FileInputStream("C:\\Aspose\\Aspose_Input\\sheet.xml"));

pdf.save(new FileOutputStream("C:\\Aspose\\Aspose_Input\\sheet.pdf"));

}catch (Exception e) {

e.printStackTrace();

return false;

}

return true;

}

Also PFA the xls file that i am trying to convert to PDF.

Hi,

Which version of Aspose.Pdf for Java you are using? Please try latest version for Aspose.Pdf for Java v2.5 as the API structures is changed a bit in it. I am using Aspose.Cells for Java v2.1.2.x and Aspose.Pdf for Java v2.5 and it works fine.

Here is my sample code, kindly check it (see the package import section too). I have also attached my output pdf file here when running sample code with you excel file.

Sample Program:

import java.io.*;
import com.aspose.cells.;
import aspose.pdf.
;

public class Pdf1 {


public static void main(String[] args) throws Exception
{

//Instantiate the Workbook object
Workbook workbook = new Workbook();
workbook.open(“d:\files\Mail_Format.xls”);
//Save the document in Aspose.Pdf.Xml format
workbook.save(“d:\files\Mail_Format.xml”, FileFormatType.ASPOSE_PDF);
//Bind the XML file (containing spreadsheet data) with the Pdf object
Pdf pdf = new Pdf();
pdf.bindXML(“d:\files\Mail_Format.xml”, null);
//Create the PDF document by calling its save method
pdf.save(“d:\files\Mail_Format.pdf”);

}

}



Kindly let us know if you still find any issue.

Thank you.