How can I convert a text file to a pdf?

Hi,

How can I convert a text file to a pdf file ?

I am using Aspose 2.9.0

Hello Sriman,

Thanks for your interest in our products.

Please visit the following link for information on Converting text file to PDF.

Hi,

I need to convert the attached text file to a PDF. I have written the following code but not able to convert it to pdf.

public static void convertTextFiles()throws Exception{

//.txt file

String inputFile = "C:\\ziptest\\Parent\\Child2\\AsposeDelegate.txt";

String data = readTextFileAsChars(new File(inputFile));

//System.out.println(data);

Pdf pdf1 = new Pdf();

Section sec1 = pdf1.getSections().add();

Text text1 = new Text(sec1,data);

sec1.getParagraphs().add(text1);

pdf1.save("C:\\AsposeTest\\aug\\4.pdf");

}

static public String readTextFileAsChars(File aFile) {

StringBuilder contents = new StringBuilder();

try {

BufferedReader input = new BufferedReader(new FileReader(aFile));

try {

char[] chars = new char[1024];

int numRead = 0;

while( (numRead = input.read(chars)) > -1){

contents.append(String.valueOf(chars));

}

}

finally {

input.close();

}

}

catch (IOException ex){

ex.printStackTrace();

}

return contents.toString();

}

But I am getting the following exception :

AsposeDelegate Error in main

java.lang.NullPointerException

at aspose.pdf.xml.Ack.a(SourceFile:2538)

at aspose.pdf.xml.Ack.a(SourceFile:2430)

at aspose.pdf.xml.Acm.a(SourceFile:494)

at aspose.pdf.xml.Acc.a(SourceFile:784)

at aspose.pdf.xml.Aar.a(SourceFile:97)

at aspose.pdf.xml.Aba.a(SourceFile:112)

at aspose.pdf.Pdf.save(SourceFile:923)

at AsposeFileConverter.convertHugeTextFilesByFileReader(AsposeFileConverter.java:206)

at AsposeFileConverter.convertFile(AsposeFileConverter.java:261)

at AsposeDelegate.convertFile(AsposeDelegate.java:69)

at AsposeDelegate.main(AsposeDelegate.java:135)

Even I tried your other approach to convertHugeText file still getting the same Exception.

Code Snippet for Huge text file :

public static void convertHugeTextFilesByFileReader() throws Exception{

String inputFile = "C:\\ziptest\\Parent\\Child2\\AsposeDelegate.txt";

Pdf pdf1 = new Pdf();

Section sec1 = pdf1.getSections().add();

FileInputStream fstream = new FileInputStream(inputFile);

DataInputStream in = new DataInputStream(fstream);

BufferedReader br = new BufferedReader(new InputStreamReader(in));

String strLine;

while ((strLine = br.readLine()) != null)

{

Text text1 = new Text(sec1,strLine);

sec1.getParagraphs().add(text1);

}

in.close();

pdf1.save("C:\\AsposeTest\\aug\\41.pdf");

}

But it works when the file line size is reduced to 25-30 lines.

Please help...

Is there maximum allowable size for a Section ?

Hello Sriman,

Thanks for your interest in our products.

I have tested the scenario and I am able to notice that NullPointerException is being generated when converting the source Text file (that you have shared) into PDF format. For the sake of correction, I have logged it in our issue tracking system as PDFJAVA-28698. We will investigate this issue in details and will keep you updated on the status of a correction.

I am not entirely certain why this issue is occurring. In fact there is no specific limitation regarding source document size.

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

We apologize for your inconvenience.

ANy Update on this issue ?

Hello Sriman,

Thanks for your patience.

I am pleased to inform you that the issue reported earlier has been fixed and its HotFix will be included in upcoming release version of Aspose.Pdf for Java. Please be patient and spare us little time. As soon as the new version becomes available, we would be more than happy to you update you with the status of correction. Your patience and comprehension is greatly appreciated in this regard.

The issues you have found earlier (filed as 28698 ) have been fixed in this update.


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