itextsharp does not add loop pages

Asked

Viewed 222 times

0

I put my code inside a FOR to display several pages according to its count. Turns out it only shows the last page, and not all that 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")
  • would not be html += to concatenate ?

1 answer

0


I found this example that worked 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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.