I created a webforms page that issued many qr voucher codes, what I want is that I can print the vouchers one by one page from the database I have. here's the code I've tried to make
Private Sub MySub(Param As String)
Try
Dim obj As New ReportObjects
Dim dt0 As New DataTable
Dim ds As New DataSet
ds = obj.MyStoredProcedure(Param)
obj.Dispose()
dt0 = ds.Tables(0)
obj.Dispose()
dt0.Dispose()
ds.Dispose()
For i As Integer = 0 To dt0.Rows.Count - 1
Dim qrGenerator As QRCodeGenerator = New QRCodeGenerator()
Dim qrCode As QRCodeGenerator.QRCode = qrGenerator.CreateQrCode(dt0.Rows(i).Item("VoucherNo"), QRCodeGenerator.ECCLevel.Q)
Using bitMap As Bitmap = qrCode.GetGraphic(20)
Using ms As MemoryStream = New MemoryStream()
bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
byteImage = ms.ToArray()
End Using
End Using
Dim base64 As String = Convert.ToBase64String(byteImage)
Dim imageBytes As Byte() = Convert.FromBase64String(base64)
Dim image As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(imageBytes)
Using memoryStream As System.IO.MemoryStream = New System.IO.MemoryStream()
Dim document As Document = New Document(PageSize.A4, 1.0F, 1.0F, 1.0F, 1.0F)
Dim writer As PdfWriter = PdfWriter.GetInstance(document, memoryStream)
document.Open()
document.NewPage()
document.Add(image)
document.Add(New Phrase("Valid From : " & dt0.Rows(i).Item("StartDT").ToString() & " To " & dt0.Rows(i).Item("EndDT").ToString()))
document.Close()
Dim bytes As Byte() = memoryStream.ToArray()
memoryStream.Close()
Response.Clear()
Response.ContentType = "application/pdf"
Response.AddHeader("Content-Disposition", "attachment; filename=Image.pdf")
Response.ContentType = "application/pdf"
Response.Buffer = True
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.BinaryWrite(bytes)
Response.End()
End Using
Next
Catch ex As Exception
Throw New Exception(ex.Message)
End Try
End Sub
The problem I encountered with my code is the code doesn't produce multiple pages. It produce just 1 page and the data is the first row of my table. I used iTextSharp for generating PDF.
Your answer will be so helpful. Thank you