itextsharp does not add pages in loop

0

I put my code inside a FOR to display several pages according to its count. It turns out that it shows only the last page, not all that it should.

For s  = 0 To 9           
html = "<p> "& s & "</p>"

'PDF                
Using reader As TextReader = New StringReader(html)
 Dim pdfwrite As PdfWriter = PdfWriter.GetInstance(document, Response.OutputStream)'                                            
 document.Open()
 document.NewPage()'                                                       
 XMLWorkerHelper.GetInstance().ParseXHtml(pdfwrite, document, reader)                     
End Using                               
next
document.close()

'Visualiza
Dim resp As HttpResponse = Me.Response
resp.ContentType = "application/pdf"
resp.AddHeader("Content-Disposition", "filename=sigov" & Now.Day & Now.Month & Now.Year & Now.Second & ".pdf")
    
asked by anonymous 29.01.2016 / 10:21

1 answer

0

I found this example to work perfectly.

Sub Main()
Using doc = New Document(PageSize.A4, 50, 50, 50, 50)
        Using writer As PdfWriter = PdfWriter.GetInstance(doc, Response.OutputStream)
        doc.Open()
        doc.AddTitle("PPN Rebate Invoice")
        doc.AddAuthor("PPN")            
        for i as integer = 0 to 9
          Dim html = "<!DOCTYPE html><html><head><title>Test</title></head><body><p>This is a test:" & i & "</p></body></html>"
          Using reader As TextReader = New StringReader(html)
              XMLWorkerHelper.GetInstance().ParseXHtml(writer, doc, reader)
              doc.NewPage
          End Using           
        Next
        doc.Close() 
        'if i = 9 then doc.NewPage()
    End Using        
End Using
End Sub
    
29.01.2016 / 20:39