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

Free Support Forum - aspose.com

Pdf for Java - Exception

Hi,
I get the following exception when generating PDF with latest version.

java.lang.NullPointerException
at aspose.pdf.c.p.do(Unknown Source)
at aspose.pdf.c.aa.if(Unknown Source)
at aspose.pdf.e.m.a(Unknown Source)
at aspose.pdf.e.bm.a(Unknown Source)
at aspose.pdf.e.a1.a(Unknown Source)
at aspose.pdf.e.bf.a(Unknown Source)
at aspose.pdf.e.ap.a(Unknown Source)
at aspose.pdf.Pdf.save(Unknown Source)
at AdePdf.main(AdePdf.java:24)

Please help to correct.

Thanks

Hi,

I am experiencing the same problem.

The following is the process I followed:

Workbook myWorkbook = new Workbook();
myWorkbook.open("/Users/mark/invoice.xls");
myWorkbook.save("/Users/mark/invoice.xml",FileFormatType.ASPOSE_PDF);
Pdf pdf = new Pdf();
pdf.bindXML("/Users/mark/invoice.xml");
pdf.save("/Users/mark/invoice.pdf");

NullPointerException on the save op.
Really need to get past this. Any help would be appreciated.

Thanks,
Mark

Hello Mark,

Can you please share the source Excel Worksheet so that we can test the scenario at our end.

We apologize for your inconvenience.

I have attached the source worksheet (invoice.xls)
Also attached is the Aspose XML file generated from the API. (invoice.xml)

Also one correction to the code posted previously:
pdf.bindXML("/Users/mark/invoice.xml",null);

Thanks for the quick response.
Hope we can resolve this issue.

–Mark

Hello Mark,

Thanks for considering Aspose.

I've tried converting the Excel worksheet that you've shared into PDF format using Aspose.Pdf for Java 2.5.0 and Aspose.Cells for Java 2.1.2.3 and as per my observation, the PDF document is being generated without any problem. The resultant PDF and Aspose.Cells for Java 2.1.2.3 are in attachment, please take a look.

I've used the following code snippet.

[Java]

aspose.pdf.License lic = new aspose.pdf.License();
com.aspose.cells.License lic2 = new com.aspose.cells.License();
try {
lic.setLicense(new FileInputStream(new File("E:/Aspose.Total.Java.lic")));
lic2.setLicense(new FileInputStream(new File("E:/Aspose.Total.Java.lic")));
} catch (Exception e) {
System.out.println(e.getMessage());
}

Workbook workbook = new Workbook();
workbook.open("D:/pdftest/newinvoice.xls");
workbook.save(new FileOutputStream("D:/pdftest/Template_new.xml"), FileFormatType.ASPOSE_PDF);

Pdf pdf1 = new Pdf();
pdf1.bindXML("D:/pdftest/Template_new.xml", null);
pdf1.save("D:/pdftest/Template_new_Test.pdf");

I would also suggest you to visit the following link for more information on Converting to PDF Files

In case you still face any problem or you've any further query, please feel free to contact.

We apologize for your inconvenience.

I am still having the same problem. I replaced the Aspose Cells Jar file with the version you supplied. I also updated Aspose PDF to the standalone 2.5.0 version as opposed to the bundled one that came with Aspose Total. I’m using the code snippit you provided above.

java.lang.NullPointerException
at aspose.pdf.c.p.do(Unknown Source)
at aspose.pdf.c.aa.if(Unknown Source)
at aspose.pdf.e.m.a(Unknown Source)
at aspose.pdf.e.bm.a(Unknown Source)
at aspose.pdf.e.bo.a(Unknown Source)

I thought it might have been an issue with a 1.6 compiler, however I switched to 1.5 but alas the same result.

Maybe its an issue with my license? I have attached the eval license you sent me last week.
It’s strange that the expiration of the license is 2010-04-09. Can you try the test again with my license and if its a problem can you issue me with a new license?

Thanks,
Mark

I’m also wondering if this could be an obfuscation dependency issue between jar files.
Maybe if you upload the set of jars in your classpath required to run this example (namely the aspose cells, aspose pdf and dom4j jar file) and I’ll try recompiling with those jar files.

Many thanks,
Mark

Hello Mark,

I've tested the license file and its working correctly. I've been able to generate the resultant PDF document without any issue. Can you please try using the attached Jar files and share your findings.

We apologize for your inconvenience.

Still no luck. I have tried compiling and running the example on both MacOS and Linux platform. Same runtime exception in every case.

[moleary@vm-linux aspose-test]$ ./runDemo.sh
java.lang.NullPointerException
at aspose.pdf.c.p.do(Unknown Source)
at aspose.pdf.c.aa.if(Unknown Source)
at aspose.pdf.e.m.a(Unknown Source)
at aspose.pdf.e.bm.a(Unknown Source)
at aspose.pdf.e.bo.a(Unknown Source)
at aspose.pdf.e.a0.a(Unknown Source)
at aspose.pdf.e.d.a(Unknown Source)
at aspose.pdf.e.a1.a(Unknown Source)
at aspose.pdf.e.bf.a(Unknown Source)
at aspose.pdf.e.ap.a(Unknown Source)
at aspose.pdf.Pdf.save(Unknown Source)
at com.summitas.demo.AsposeDemo.main(AsposeDemo.java:49)

Here is my source:

String basePath = null;

if(args.length > 0 && args[0] != null) {
basePath = args[0];
}
else {
basePath = “/Users/mark/HDD/Splashpond/projects/inline applet vwr/testfiles/”;
}

String licenseFile = basePath + “Aspose.Total.Java.lic”;

aspose.pdf.License lic = new aspose.pdf.License();
com.aspose.cells.License lic2 = new com.aspose.cells.License();
try {
lic.setLicense(new FileInputStream(new File(licenseFile)));
lic2.setLicense(new FileInputStream(new File(licenseFile)));
} catch (Exception e) {
System.out.println(e.getMessage());
return;
}

Workbook workbook = new Workbook();
workbook.open(basePath +“invoice.xls”);
workbook.save(new FileOutputStream(basePath +“invoice_template.xml”), FileFormatType.ASPOSE_PDF);

Pdf pdf1 = new Pdf();
pdf1.bindXML(basePath +“invoice_template.xml”, null);
pdf1.save(basePath +“invoice_generated.pdf”);


any other ideas?

Thanks
Mark

I get still get this error, here is my source code.

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

import aspose.pdf.License;
import aspose.pdf.PageSize;
import aspose.pdf.Pdf;
import aspose.pdf.Section;
import aspose.pdf.Text;


public class AdePdf {
public static void main(String args[]){
//if you got a license, uncomment following lines
License lic = new License();
try {
lic.setLicense(new FileInputStream(new File(“C:\Projects\Aspose\Version XXX - Dev\lic\Aspose.Total.Java.lic”)));
}catch (Exception e) {
System.out.println(e.getMessage());
}

try{
Pdf pdf = new Pdf();
pdf.getPageSetup().setPageHeight(PageSize.A4Height);
//add a section
Section sec1 = pdf.getSections().add();
Text text1 = new Text(sec1,"seg1 ");

FileInputStream fis = new FileInputStream(“C:\Aspose PDF\aspose.pdf\ade.html”);


pdf.save(“c:\exampleOutput\adehtml.pdf”);
}catch(java.io.IOException ioe){
System.out.println(ioe.getMessage());
}
}
}

Please help to resolve.

My apologies, here is the sample code and the error message that I get, I used aspose.pdf 2.5.0 version, is there anything to do with jdk version?

import aspose.pdf.Pdf;
import aspose.pdf.Section;
import aspose.pdf.Text;


public class PdfTest {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Pdf pdf = new Pdf();
Section sec = pdf.getSections().add();
Text t1 = new Text(“Arial”);
t1.getSegments().getSegment(0).getTextInfo().setFontName(“Arial”);
sec.getParagraphs().add(t1);
pdf.save(“C:\hello.pdf”);
}
}


Error Message
==========
Exception in thread “main” java.lang.NullPointerException
at aspose.pdf.c.p.do(Unknown Source)
at aspose.pdf.c.aa.if(Unknown Source)
at aspose.pdf.e.m.a(Unknown Source)
at aspose.pdf.e.bm.a(Unknown Source)
at aspose.pdf.e.a1.a(Unknown Source)
at aspose.pdf.e.bf.a(Unknown Source)
at aspose.pdf.e.ap.a(Unknown Source)
at aspose.pdf.Pdf.save(Unknown Source)
at PdfTest.main(PdfTest.java:18)


Hi,

I've tested the scenario using Aspose.Pdf for Java 2.5.0 with JDK 1.6.0 and I'm unable to notice any problem. The resultant PDF that I've generated is in attachment, please take a look.

I'm not sure why its causing an issue at your end. Can you please share which version of JDK you're using.

We apologize for your inconvenience.

Hello Mark,

Sorry for replying you late.

Can you please confirm that, either you've tried compiling the code over Windows platform or not, other than Linux and MAC OS ? Whereas concerning to working over MAC OS and Linux platforms, can you please confirm which version of both the OS you're using ?

We apologize for your inconvenience.

With JDK1.6.0_03 I get the following error.

C:\Documents and Settings\M112395\workspace\AsposeAde\src>java PdfTest
Exception in thread “main” java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)

With jdk1.5.0_16, I get NullPointer exception as described above.Please advise

I am able to resolve this issue, I have jdk1.5 and 1.6 versions installed which was conflicting. WIth JDK1.6 it works fine. Thanks for your support.

I believe I have identified what the issue is here:
I just downloaded the latest version of Aspose Total yesterday and I ran the same example again.

* It works on Windows (JDK 1.6)
* Fails with Nullpointer on OSX Snowleopard
* Fails with Nullpointer on CentOS
* Fails with Nullpointer on RHEL5

I have tried JDK 1.6 v10 and JDK 1.6 v20 on both Linux platforms with no luck.
The stock version of Java on Snow Leopard is 1.6

Since our client base are a mix of Windows and Mac users, it would be critical for us to address the Mac OSX case.

The Nullpointer occurs on the workbook.save operation.

Can you possibly test compiling and running the example on Mac OSX to reproduce and create an issue to get this fixed? We would like to move ahead with a purchase of your software if this can be fixed.

Thanks,
Mark

Hello Mark,

Thanks for sharing the detailed information. We will look into the details of this problem and will keep you updated on the status of correction.

We apologize for your inconvenience.