Created
March 3, 2009 15:49
-
-
Save sonukapoor/73376 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function CreatePDF(ByVal items As Dictionary(Of String, Object)(), ByVal language As String) As String | |
Dim pdf As Pdf = New Pdf() | |
Dim license As License = New License | |
license.SetLicense(Server.MapPath("~/Licenses/Aspose.Custom.lic")) | |
Dim section As Section = pdf.Sections.Add() | |
'section.PageInfo.PageWidth = 360 ' 1 inch = 72 points = 5 * 72 = 360 | |
'section.PageInfo.PageHeight = 504 | |
section.PageInfo.PageWidth = 450 | |
section.PageInfo.PageHeight = 300 | |
section.PageInfo.Margin.Left = 20 | |
section.PageInfo.Margin.Right = 20 | |
section.PageInfo.Margin.Top = 5 | |
section.PageInfo.Margin.Bottom = 5 | |
Dim table As Aspose.Pdf.Table = New Aspose.Pdf.Table() | |
section.Paragraphs.Add(table) | |
table.ColumnWidths = "360 50" | |
Dim style As String = String.Empty | |
Dim alu As String = String.Empty | |
Dim desc As String = String.Empty | |
Dim color As String = String.Empty | |
Dim price As String = String.Empty | |
Dim si As StyleInfo = Nothing | |
Dim pdfRow As Row = Nothing | |
For Each item As Dictionary(Of String, Object) In items | |
alu = item("ALU") | |
style = item("Style") | |
si = PrintCards.GetDescriptionColorByALU(alu, language) | |
desc = si.Description | |
color = si.ColorName | |
price = PrintCards.GetPriceByALU(alu) | |
AddItem(style, price, desc, color, table, pdf) | |
Next | |
Dim filename As String = String.Concat(Guid.NewGuid.ToString.Replace("-", ""), ".pdf") | |
pdf.Save(Server.MapPath(String.Concat("~/filestmp/", filename))) | |
Return filename | |
End Function | |
Function GetStyleTextInfo() As TextInfo | |
Dim info As New TextInfo | |
info.FontSize = 24 | |
info.FontName = "HelveticaNeueLT Std Med" | |
Return info | |
End Function | |
Private Sub AddItem(ByVal style As String, ByVal price As Integer, ByVal desc As String, ByVal color As String, ByRef table As Table, ByRef pdf As Pdf) | |
Dim lastCellMarginInfo As New MarginInfo | |
lastCellMarginInfo.Bottom = 10 | |
Dim styleRow As Row = table.Rows.Add() | |
Dim styleCell As Cell = AddCell(style, styleRow) | |
styleCell.DefaultCellTextInfo = GetStyleTextInfo() | |
Dim priceCell As Cell = AddCell(String.Concat("$ ", price), styleRow) | |
priceCell.Alignment = AlignmentType.Right | |
priceCell.DefaultCellTextInfo = GetStyleTextInfo() | |
Dim descRow As Row = table.Rows.Add() | |
AddCell(desc, descRow) | |
Dim colorRow As Row = table.Rows.Add() | |
Dim lastCell As Cell = AddCell(color, colorRow) | |
lastCell.Padding = lastCellMarginInfo | |
Dim h As Single = table.GetHeight(pdf) | |
If h >= 245 Then | |
table.Rows.Remove(styleRow) | |
table.Rows.Remove(descRow) | |
table.Rows.Remove(colorRow) | |
table = AddTable(pdf) | |
table.Rows.Add(styleRow) | |
table.Rows.Add(descRow) | |
table.Rows.Add(colorRow) | |
End If | |
End Sub | |
Sub SetFont(ByVal t As Text) | |
Dim info As TextInfo = t.TextInfo.Clone | |
info.FontSize = 13 | |
info.FontName = "HelveticaNeueLT Std Med" | |
t.TextInfo = info | |
End Sub | |
Function AddCell(ByVal data As String, ByRef row As Row) As Cell | |
Dim cell As Cell = row.Cells.Add | |
Dim text As Text = New Text(data) | |
SetFont(text) | |
cell.Paragraphs.Add(text) | |
Return cell | |
End Function | |
Function AddTable(ByRef pdf As Pdf) As Table | |
Dim section As Section = pdf.Sections.Add() | |
section.PageInfo.PageWidth = 450 | |
section.PageInfo.PageHeight = 300 | |
section.PageInfo.Margin.Left = 20 | |
section.PageInfo.Margin.Right = 20 | |
section.PageInfo.Margin.Top = 5 | |
section.PageInfo.Margin.Bottom = 5 | |
section.IsNewPage = True | |
Dim table As Aspose.Pdf.Table = New Aspose.Pdf.Table() | |
section.Paragraphs.Add(table) | |
table.ColumnWidths = "360 50" | |
Return table | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment