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

Free Support Forum - aspose.com

java.awt.HeadlessException - Aspose.Words.jdk14 and jdk15

Hi ,

We are getting java.awt.HeadlessException in unix environment for Aspose.Words.

We have set -Djava.awt.headless=true

Are we missing anything?

It is running on weblogic10.3

Thanks,

Sunam

Hello

Thanks for your inquiry. Could you please provide me details of the exception? Please attach stack trace of the exception.

How can I reproduce the problem on my side?

Best regards,

Here the code.

The input the rtf document as byte[].

public static byte [] rtfToPdfConverter(byte [] input) throws Exception{
byte[] inputData=null;
InputStream ins=null;
ByteArrayOutputStream out=null;
Document doc =null;
String osName=null;
License license=null;
inputData=input;
osName= System.getProperty(“os.name”);
if(!osName.equalsIgnoreCase(“Windows XP”)){
FontSettings.setFontsFolder("/bnz/oracle/fonts",true);
license= new License();
license.setLicense("/bnz/oracle/fonts/Aspose.Words.lic");
}
ins = new ByteArrayInputStream(inputData);
doc = new Document(ins);
out=new ByteArrayOutputStream();
doc.save(out, SaveFormat.PDF);
inputData=out.toByteArray();
ins.close();
out.close();
return inputData;
}

Hi

Thank you for additional information. But could you please also attach your input document here for testing? We will check the issue and provide you more information.

Best regards,

Here is the main class: (input as argument)

java classname .rtf .pdf

Attachement has the sample rtf.

public static void main(String args[]){

//String myDir="F:/Project_Info/CreditDecisioning/BI_Publisher/testrtf/Test/";

try {

File file=new File(args[0] + args[1]);

InputStream is = new FileInputStream(file);

long length = file.length();

if (length > Integer.MAX_VALUE) {

System.out.println("File is too large");

}

byte[] bytes = new byte[(int)length];

// Read in the bytes

int offset = 0;

int numRead = 0;

while (offset < bytes.length

&& (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {

offset += numRead;

}

// Ensure all the bytes have been read in

if (offset < bytes.length) {

throw new IOException("Could not completely read file "+file.getName());

}

// Close the input stream and return bytes

is.close();

//bytes

InputStream ins = new ByteArrayInputStream(bytes);

//String input = new String(bytes, "UTF8");

Document doc = new Document(ins);

ByteArrayOutputStream out=new ByteArrayOutputStream();

doc.save(out, SaveFormat.PDF);

byte data[]=out.toByteArray();

File f=new File(args[0] + args[2]);

FileOutputStream fop=new FileOutputStream(f);

fop.write(data);

fop.close();

out.close();

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

Hi

Thank you for additional information. But I cannot reproduce the problem on my side. I used the latest version of Aspose.Words for testing. You can download the latest version from here:

http://www.aspose.com/community/files/72/java-components/aspose.words-for-java/category1378.aspx

I checked your code on in Windows7 and Ubuntu 11.10 environments.

Best regards,