Imports Aspose.Pdf
Imports Aspose.Pdf.Text
Imports Aspose.Pdf.DOM
Imports System.IO
Imports System.Web
Imports System.Web.Services
Public Class TestReceipt
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim license As Aspose.Pdf.License = New Aspose.Pdf.License
license.SetLicense(“Aspose.Total.lic”)
Dim pdfGen As Aspose.Pdf.Generator.Pdf = New Aspose.Pdf.Generator.Pdf()
Dim section1 As Aspose.Pdf.Generator.Section = pdfGen.Sections.Add()
Dim margin As Aspose.Pdf.Generator.MarginInfo = New Aspose.Pdf.Generator.MarginInfo()
margin.Top = 50.0F
margin.Left = 65.0F
margin.Right = 10.0F
margin.Bottom = 50.0F
'Dim sec1 As Aspose.Pdf.Generator.Section = pdfGen.Sections.Add()
'SetFooter(sec1)
'
’ Get receipt data…
'
Dim pid As Integer = 12 ’ Payment ID
'Dim pid As Integer = 19
'Dim oDbf As New DBFunctions
'Dim cSql As String = “exec cr2_Receipts " & pid.ToString
'Dim dt As DataTable = oDbf.ExecDatatable(cSql)
Dim wrk As String = “”
Dim regid As String = “”
Dim memid As String = “”
Dim lu As String = “8888”
Dim htmlString As New StringBuilder(”“)
htmlString.Append(”
“)
htmlString.Append(”
TEST Conference
“) htmlString.Append(”
Local Union: " & lu & “
”) htmlString.Append(“
”)
Dim text1 As New Aspose.Pdf.Generator.Text(htmlString.ToString)
text1.TextInfo.IsFontEmbedded = True
section1.Paragraphs.Add(text1)
section1.PageInfo.Margin = margin
section1.IsLandscape = True
text1.IsHtmlTagSupported = True
htmlString.Clear()
Dim amt As Double = 0.0
Dim ii As Integer = 0
For ii = 0 To 2
'
’ Set title only on first item…
'
If ii = 0 Then
'SetTitle(sec1, dt)
htmlString.Append(“”)
'htmlString.Append(“
”)
htmlString.Append(“
”)
htmlString.Append(“
”)
htmlString.Append(“
”)
htmlString.Append(“
”)
htmlString.Append(“
”)
htmlString.Append(“
”)
htmlString.Append(“
”)
'htmlString.Append(“
”)
'htmlString.Append(“
”)
End If
amt = amt + 1
If regid <> “” Then regid &= “|”
If memid <> “” Then memid &= “|”
regid &= 9 + ii
memid &= 63 + ii
Dim member As String
If ii = 0 Then member = “Twiddy, J. Sidlow”
If ii = 1 Then member = “Finney, Charles”
If ii = 2 Then member = “Idiots, Morons R.”
htmlString.Append(“
”)
htmlString.Append(“
”)
htmlString.Append(“
”)
htmlString.Append(“
”)
htmlString.Append(“
”)
htmlString.Append(“
”)
Next
'htmlString.Append(“
Name | Phone | Email | Amount |
|
” & member & “ | 999-999-9999 | bill_beers@ibew.org | ” & FormatCurrency(amt, 0) & “ |
”)
’ the end of it…
htmlString.Append(“
”) htmlString.Append(“” & FormatCurrency(amt, 0) & “”)
'
’ Summary…
'
htmlString.Append(“
”) 'If dt(0)(“TransType”) = “CHK” Then
’ htmlString.Append(“Make Check To…Federal Reserve”)
’ htmlString.Append(“ ”)
’ wrk = dt(0)(“Payable2”)
’ wrk = wrk.Replace(vbCrLf, “
”)
’ htmlString.Append(“Send Check To…” & wrk & “”)
’ htmlString.Append(“ ”)
’ htmlString.Append(“Notice: Registration is not final until check is received.”)
'End If
Dim trantype As String = “CC”
Dim ccType As String = “2”
If trantype = “CC” Then
Select Case ccType
Case “1”
wrk = “Master Card”
Case “2”
wrk = “VISA”
Case “3”
wrk = “American Express”
Case “4”
wrk = “Discover Card”
End Select
htmlString.Append(“” & wrk & " ending in…1111“)
htmlString.Append(”Name on Card…J. Sidlow Twiddy“)
htmlString.Append(” “)
wrk = “a09f4be7-6fd7-44e4-8741-a8708eef7a22”
htmlString.Append(”Transaction ID…" & wrk & “”)
End If
htmlString.Append(“ ”)
htmlString.Append(“Transaction Date…09/04/2015”)
htmlString.Append(“”)
Dim text2 As New Aspose.Pdf.Generator.Text(htmlString.ToString)
section1.Paragraphs.Add(text2)
text2.IsHtmlTagSupported = True
text2.TextInfo.IsFontEmbedded = True
SetFooter(section1, “666”, “7777”)
'
’ Generate Output…
'
Try
Dim ms As New System.IO.MemoryStream()
pdfGen.Save(ms)
Response.Clear()
Response.ClearHeaders()
Response.ClearContent()
Response.Charset = “UTF-8”
Dim downloadBytes As Byte() = ms.ToArray()
Dim msec As String = DateTime.UtcNow.ToString
'Dim fmt As String = “ConfReceipt_LU” & lu & “" & dt(0)(“ConfID”) & "” & pid.ToString & “.pdf”
Dim fmt As String = “ConfReceipt_LU” & lu & “" & msec & "” & pid.ToString & “.pdf”
Response.AddHeader(“Content-Length”, ms.Length.ToString())
Response.AddHeader(“Content-Type”, “application/pdf”)
Response.AddHeader(“Content-Disposition”, [String].Format(“inline; filename={0}”, fmt))
Response.BinaryWrite(downloadBytes)
ms.Close()
ms = Nothing
downloadBytes = Nothing
Response.Flush()
Response.End()
Catch ex As Exception
Dim msg As String = ex.Message
Response.Write(ex.Message)
Response.Write(ex.StackTrace)
Response.End()
End Try
End Sub
Private Sub SetTitle(sec As Aspose.Pdf.Generator.Section)
Dim titletxt As Aspose.Pdf.Generator.Text = New Aspose.Pdf.Generator.Text
sec.Paragraphs.Add(titletxt)
Dim titleseg As Aspose.Pdf.Generator.Segment = titletxt.Segments.Add(“Test Conference”)
titleseg.TextInfo.FontSize = 20
End Sub
Private Sub SetFooter(sec As Aspose.Pdf.Generator.Section, regid As String, memid As String)
Dim footer As Aspose.Pdf.Generator.HeaderFooter = New Aspose.Pdf.Generator.HeaderFooter(sec)
sec.OddFooter = footer
sec.EvenFooter = footer
Dim tab1 As Aspose.Pdf.Generator.Table = New Aspose.Pdf.Generator.Table()
footer.Paragraphs.Add(tab1)
tab1.ColumnWidths = “233 233 233”
tab1.DefaultCellBorder = New Aspose.Pdf.Generator.BorderInfo(Aspose.Pdf.Generator.BorderSide.All, 0.0F)
'Dim txt As Aspose.Pdf.Generator.Text = New Aspose.Pdf.Generator.Text(“Page: ($p of $P )”)
Dim row1 As Aspose.Pdf.Generator.Row = tab1.Rows.Add()
row1.Cells.Add(“Page: ($p of $P )”)
row1.Cells(0).Alignment = Aspose.Pdf.Generator.AlignmentType.Left
Dim wrk As String = “Conf ID: 114 | PID: 12”
row1.Cells.Add(" ")
row1.Cells(1).Alignment = Aspose.Pdf.Generator.AlignmentType.Center
row1.Cells.Add(“Date: $D”)
row1.Cells(2).Alignment = Aspose.Pdf.Generator.AlignmentType.Right
'footer.Paragraphs.Add(tab1)
Dim row2 As Aspose.Pdf.Generator.Row = tab1.Rows.Add()
row2.Cells.Add(regid)
row2.Cells(0).Alignment = Aspose.Pdf.Generator.AlignmentType.Left
row2.Cells.Add(wrk)
row2.Cells(1).Alignment = Aspose.Pdf.Generator.AlignmentType.Center
row2.Cells.Add(memid)
row2.Cells(2).Alignment = Aspose.Pdf.Generator.AlignmentType.Right
'Dim txt2 As Aspose.Pdf.Generator.Text = New Aspose.Pdf.Generator.Text(“Date: $D”)
'footer.Paragraphs.Add(txt2)
End Sub
End Class