Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

vb.net - itextsharp: how do i add a new page and write to it?

in vb.net i filled up the first page of a pdf document, how do i start from the second page?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Document document = new Document(PageSize.A4, 0, 0, 50, 50);
System.IO.MemoryStream msReport = new System.IO.MemoryStream();

try {
    // creation of the different writers
    PdfWriter writer = PdfWriter.GetInstance(document, msReport);

    // we add some meta information to the document
    document.AddTitle("My Title");  
    document.AddAuthor("Me");
    document.Open();

    for (int i = 1; i <= 5; i++)
    {
        document.NewPage();
        iTextSharp.text.Table datatable = new iTextSharp.text.Table(3);
        datatable.Padding = 2;
        datatable.Spacing = 0;
        float[] headerwidths = { 6, 20, 32 };
        datatable.Widths = headerwidths;
        datatable.DefaultHorizontalAlignment = Element.ALIGN_LEFT;
        datatable.AddCell(i.ToString());
        datatable.AddCell("This is my name.");
        datatable.AddCell("0123456789");

        datatable.AddCell("No");
        datatable.AddCell("Yes");
        datatable.AddCell("No");

        document.Add(datatable);
     } 
} 
catch (Exception e) { 
    Console.Error.WriteLine(e.Message); 
} 

// we close the document 
document.Close(); 

Response.Clear(); 
Response.AddHeader("content-disposition", "attachment;filename=Export.pdf"); 
Response.ContentType = "application/pdf"; 
Response.BinaryWrite(msReport.ToArray()); 
Response.End(); 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...