> Hi Bruno, > I am V.Balajee Kishan. I need some help > from you. > > I have a requirement. On a unix machine i > have to convert existing text files to PDF's using a > java program.
Just plain ASCII that is preformatted? I would read the text line per line and add every line in a monospaced font (adjust the size to the number of chars per line).
Just a quick sample (you could improve it):
import java.io.*; import com.lowagie.text.*; import com.lowagie.text.pdf.PdfWriter;
public class Txt2Pdf {
public static void main(String[] args) {
if (args.length < 2) {
System.err.println("Wrong number of parameters: java Txt2Pdf
source.txt destination.pdf [PORTRAIT | LANDSCAPE]");
}
try {
String line = null;
Document document;
Font f;
if (args[2] != null && "LANDSCAPE".equals(args[2])) {
f = FontFactory.getFont(FontFactory.COURIER, 10);
document = new Document(PageSize.A4.rotate(), 36, 9, 36, 36);
}
else {
f = FontFactory.getFont(FontFactory.COURIER, 11);
document = new Document(PageSize.A4, 72, 36, 36, 36);
}
BufferedReader in = new BufferedReader(new FileReader(args[0]));
PdfWriter.getInstance(document, new FileOutputStream(args[1]));
document.open();
while ((line = in.readLine()) != null) {
document.add(new Paragraph(12, line, f));
}
document.close();
}
catch(IOException ioe) {
System.err.println("Fout: " + ioe.getMessage());
}
catch(DocumentException de) {
System.err.println("Fout: " + de.getMessage());
}
}
}
------------------------------------------------------- This SF.net email is sponsored by: Etnus, makers of TotalView, The best thread debugger on the planet. Designed with thread debugging features you've never dreamed of, try TotalView 6 free at www.etnus.com. _______________________________________________ iText-questions mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/itext-questions
