0

我正在尝试将一段文本添加到现有的 PDF 模板中。

我希望能够设置左边距和右边距,但是文本的数量是不确定的,所以我需要相对于输入文本扩展框。

我已经设法在模板上定位文本区域并插入文本,但是这样做需要我明确设置文本区域的底线位置。

这是我到目前为止的代码(pdfStamper是预定义的):

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();
4

1 回答 1

0

好的,我已经尝试过其他解决方案(不起作用)。他们来了:

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));

这会将一张桌子放在所需的位置,并具有所需的宽度。但是,如果该一页上的文本太多,我希望它扩展到下一页 - 它没有。我已经尝试传递WriteSelectedRows一个可选的画布数组(pdfstamper.GetUnderContent(1)pdfstamper.GetUnderContent(2)),但这只会引发一个Index was outside the bounds of the array异常 - 但即使它确实有效,我也不知道它是否会做我想要的。

或者有这个:

PdfContentByte over;
over = pdfstamper.GetOverContent(1);
over.BeginText();
over.SetTextMatrix(20, 300);
over.ShowText(report.AutonomyText);
over.EndText();

但是文本只是离开了页面的一侧。

于 2009-08-03T10:21:09.593 回答