0

我发现这段代码可以将文本放在页面上的特定位置。

ColumnText ct = new ColumnText(cb);
Phrase myText = new Phrase("TEST paragraph\nNewline");
ct.SetSimpleColumn(myText, 34, 750, 580, 317, 15, Element.ALIGN_LEFT);
ct.Go();

现在我希望在 forloop 中为一系列文本这样做。我有

columnText ct = new ColumnText(cb)
Phrase myText; int x = 34; int y = 750;
for(int i = 0; i<5; i++){
  myText = new Phrase("TEST paragraph\nNewline");
  ct.SetSimpleColumn(myText, x, y, 580, 317, 15, Element.ALIGN_LEFT);
  ct.Go();
  x += 10;
  y+= 12;
}

但这给了我一个错误,因为文档无法创建。

请问我该怎么做?

4

1 回答 1

1

尝试将对象创建移动到循环中:

//Declare ct
columnText ct;
Phrase myText; int x = 34; int y = 750;
for(int i = 0; i<5; i++){
  //Instantiate ct
  ct = new ColumnText(cb);
  myText = new Phrase("TEST paragraph\nNewline");
  ct.SetSimpleColumn(myText, 34, 750, 580, 317, 15, Element.ALIGN_LEFT);
  ct.Go();
  x += 10;
  y += 12;
}
于 2013-01-14T20:24:18.100 回答