itextsharp: how do i add a new page and write to it?

后端 未结 2 423
春和景丽
春和景丽 2020-12-18 01:05

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

2条回答
  •  佛祖请我去吃肉
    2020-12-18 01:48

    Do not mark this as the answer, this is just gmcalab's code converted to VB for your conveniance. His example answers your question quite handily.

    Dim document As New Document(PageSize.A4, 0, 0, 50, 50) 
    Dim msReport As New System.IO.MemoryStream() 
    
    Try 
        ' creation of the different writers 
        Dim writer As PdfWriter = PdfWriter.GetInstance(document, msReport) 
    
        ' we add some meta information to the document 
        document.AddTitle("My Title") 
        document.AddAuthor("Me") 
        document.Open() 
    
        For i As Integer = 1 To 5 
            document.NewPage() 
            Dim datatable As New iTextSharp.text.Table(3) 
            datatable.Padding = 2 
            datatable.Spacing = 0 
            Dim headerwidths As Single() = {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) 
        Next 
    Catch e As Exception 
        Console.[Error].WriteLine(e.Message) 
    End Try 
    
    ' 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]() 
    

提交回复
热议问题