我正在尝试使用C#和iTextSharp将pdf页面分成两部分。
执行此操作后,我想首先将值添加到第一部分,然后添加到第二部分。
我用Google搜索并了解MultiColumnText
但是在使用它时却给出了错误。我使用的是版本5.5.0
。
以下是代码:
MultiColumnText columns = new MultiColumnText();
//float left, float right, float gutterwidth, int numcolumns
columns.AddRegularColumns(36f, doc.PageSize.Width - 36f, 24f, 2);
Paragraph para = new Paragraph(text, new Font(Font.NORMAL, 8f));
para.SpacingAfter = 9f;
para.Alignment = Element.ALIGN_JUSTIFIED;
for (int i = 0; i < 8; i++)
{
columns.AddElement(para);
}
doc.Add(columns);
我在第一行遇到错误:MultiColumnText columns = new MultiColumnText();
如何在此dll中使用此代码?请帮帮我!
更新了代码..
public static void paraPDF(){
//string pdfpath = "D:\\hello\\12.pdf";
string imagepath = "D:\\Bill\\Hello.pdf";
Document doc = new Document();
try
{
string TEXT = "This is some long paragraph that will be added over and over again to prove a point.";
Rectangle[] COLUMNS = {
new Rectangle(36, 36, 290, 806),
new Rectangle(305, 36, 559, 806)
};
PdfWriter writer2= PdfWriter.GetInstance(doc, new FileStream(imagepath, FileMode.Create));
doc.Open();
PdfContentByte canvas = writer2.DirectContent;
ColumnText ct = new ColumnText(canvas);
int side_of_the_page = 0;
ct.SetSimpleColumn(COLUMNS[side_of_the_page]);
int paragraphs = 0;
while (paragraphs < 30)
{
ct.AddElement(new Paragraph(String.Format("Paragraph %s: %s", ++paragraphs, TEXT)));
while (ColumnText.HasMoreText(ct.Go()))
{
if (side_of_the_page == 0)
{
side_of_the_page = 1;
canvas.MoveTo(297.5f, 36);
canvas.LineTo(297.5f, 806);
canvas.Stroke();
}
else
{
side_of_the_page = 0;
doc.NewPage();
}
ct.SetSimpleColumn(COLUMNS[side_of_the_page]);
doc.Close();
}
}