views:

270

answers:

1

I have used IText(Sharp) to make PDFs from raster images but have never used IText to build text based PDF's.

In this new scenario, I have N words of ASCII text that I need to add as text pages to a new PDF. Each page should be 8.5 x 11, .5 margins, using some monospaced font. Is IText(Sharp) smart enough to automatically apply line and page breaks where necessary or do I need to do this manually?

Are their any good IText tutorials for this scenario?

thanks!

scottm

A: 

ITextSharp is smart enough to do this; just do it like this:

Document document = new Document(PageSize.LETTER);
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(pdfName, FileMode.Create));
document.Open();
document.Add(new Paragraph(report));
document.Close();

Where pdfName is the name of the pdf you want to save, and report is a string containing the text you want to print. It will automatically apply line and page breaks. I think the default is to use a monospaced font, but if you have trouble with that, let me know and I will add an example of setting the font.

Matthew Talbert