2013-01-14 26 views
0

我发现此代码将文本放置在页面上的特定位置。ItextSharp:在页面中循环定位文本

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

现在我想在forlooop这样做一系列文本。我有

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

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

我该怎么做?

回答

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