try{
StringBuffer sb = new StringBuffer(1024);
BufferedReader reader = new BufferedReader(new FileReader("test.txt"));
int ch = -1;
while( (ch = reader.read()) > -1){
sb.append((char)ch);
}
reader.close();
//Instantiate Pdf pbject by calling its empty constructor
Pdf pdf1 = new Pdf();
//Create a new section in the Pdf object
Section sec1 = pdf1.getSections().add();
//Create a new text paragraph and pass the text to its constructor as argument
Text text1 = new Text(sec1,sb.toString());
sec1.getParagraphs().add(text1);
pdf1.save("d:/pdftest/Text_File_to_PDF.pdf");
}catch(java.io.IOException ioe){
System.out.println(ioe.getMessage());
}
try{
//Instantiate Pdf pbject by calling its empty constructor
Pdf pdf1 = new Pdf();
//Create a new section in the Pdf object
Section sec1 = pdf1.getSections().add();
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream("d:/pdftest/LargeText.txt");
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null)
{
//Create a new text paragraph and pass the text to its constructor as argument
Text text1 = new Text(sec1,strLine);
sec1.getParagraphs().add(text1);
}
//Close the input stream
in.close();
// Save the PDF file
pdf1.save("d:/pdftest/LargeText.pdf");
}catch(java.io.IOException ioe){
System.out.println(ioe.getMessage());
}catch(Exception e){
System.out.println(e.getMessage());
}
Copyright © 2024, NextGenUpdate.
All Rights Reserved.