1列轉換爲3列我在想,如果我能得到一些幫助這個轉換成3列每頁報告(下降到左)。iTextSharp的每
using System;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("-> Creates a PDF file with a block of Text.");
Document document = new Document(PageSize.LETTER);
try
{
PdfWriter writer = PdfWriter.GetInstance(
document,
new FileStream(@"c:\\temp\\column_example.pdf", FileMode.Create));
document.Open();
PdfContentByte cb = writer.DirectContent;
float pos;
PdfPTable table;
PdfPCell cell = new PdfPCell(new Phrase(string.Empty));
Phrase phrase;
float columnWidth = (PageSize.LETTER.Width - 36);
ColumnText ct = GetColumn(cb, columnWidth);
int status = 0;
string line = "Line{0}";
for(int i=0; i<50; i++)
{
table = new PdfPTable(1);
table.SpacingAfter = 9F;
cell = new PdfPCell(new Phrase("Header for table " + i));
table.AddCell(cell);
for (int j = 0; j < (i%2 == 0 ? 5 : 7); j++)
{
phrase = new Phrase(string.Format(line, i));
cell = new PdfPCell(phrase);
table.AddCell(cell);
}
ct.AddElement(table);
pos = ct.YLine;
status = ct.Go(true);
Console.WriteLine("Lines written:" + ct.LinesWritten + " Y-position: " + pos + " - " + ct.YLine);
if (!ColumnText.HasMoreText(status))
{
ct.AddElement(table);
ct.YLine = pos;
ct.Go(false);
}
else
{
document.NewPage();
ct.SetText(null);
ct.AddElement(table);
ct.YLine = PageSize.LETTER.Height - 36;
ct.Go();
}
}
}
catch (DocumentException de)
{
Console.Error.WriteLine(de.Message);
}
catch (IOException ioe)
{
Console.Error.WriteLine(ioe.Message);
}
finally
{
document.Close();
}
Console.ReadLine();
}
private static ColumnText GetColumn(PdfContentByte cb, float columnWidth)
{
var ct = new ColumnText(cb);
ct.SetSimpleColumn(36, 36, columnWidth, PageSize.LETTER.Height - 36, 18, Element.ALIGN_JUSTIFIED);
return ct;
}
}
}
我真的是新的itextsharp,找不到任何有關如何做到這一點的好例子。
感謝所有幫助
這看起來非常接近我需要的東西,但有沒有辦法讓文字向下,跨越右側,而不是跨越右側,然後下降? – zSynopsis
@zSysop,我上面更新了我的帖子。不是一個完整的答案,但希望它會讓你朝着正確的方向前進。 –