views:

458

answers:

1

Hi all. I am trying to add a block of text to an existing pdf template. I want to be able to set the left margin and right margin, but the amount of text is undetermined, so I need the box to expand in relation to the input text. I have managed to position the text area on the template and insert text, but doing it this way needs me to explicity set the bottom line location of the text area. Heres the code I have so far (pdfStamper is pre-defined):

BaseFont bf = BaseFont.CreateFont(BaseFont.COURIER, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

Font font = new Font(bf, 11, Font.NORMAL);

Phrase unicodes = new Phrase(reports.StringText, font);

PdfContentByte over;

over = pdfstamper.GetOverContent(1);

ColumnText ct = new ColumnText(over);

ct.SetSimpleColumn(unicodes, 19, 80, 575, 335, 10, Element.ALIGN_LEFT);

ct.Go();

Thanks!

A: 

Ok, I've had a go at other solutions (that don't work) Here they are:

PdfPTable table = new PdfPTable(1);

string text = "blab balba b balbala ";

string finalText = "TestTitle1\r\n\r\n";

for (int i = 0; i < 200; ++i)

{ finalText += text; }

table.AddCell(finalText);

table.TotalWidth = 300;

table.WriteSelectedRows(0, -1, 20, 325, pdfstamper.GetUnderContent(1));

This out puts a table in the desired place, with the desired width. But if there is too much text to fit on that one page I want it to extend to the next - which it doesnt. I have tried passing WriteSelectedRows an optional array of canvases (pdfstamper.GetUnderContent(1) and pdfstamper.GetUnderContent(2)), but this just throws a 'Index was outside the bounds of the array' exception - but I even if that did work I dont know if it would be doing what I want.

Or there's this one:

PdfContentByte over;

over = pdfstamper.GetOverContent(1);

over.BeginText();

over.SetTextMatrix(20, 300);

over.ShowText(report.AutonomyText);

over.EndText();

But the text just goes of the side of the page.