Make a PDF file from asp.net
Posted by Viral Sarvaiya on July 8, 2009
to make a pdf file hear I demonstrate as below,
you have to take a itextsharp.dll file from the following link
http://sourceforge.net/projects/itextsharp/
now the code is as follows,
Imports iTextSharp.text
Imports iTextSharp.text.pdf
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If IsPostBack = False Then
makepdf()
End If
End Sub
Sub makepdf()
Dim labelFont14 As Font = FontFactory.GetFont(FontFactory.TIMES_ROMAN, 14, Font.NORMAL)
labelFont14.Color = New iTextSharp.text.Color(0, 25, 25)
Dim labelFont12 As Font = FontFactory.GetFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL)
labelFont12.Color = New iTextSharp.text.Color(0, 25, 25)
'as like that you can define the font.
PageSize.A4.BackgroundColor = New iTextSharp.text.Color(255, 255, 255)
Dim doc As Document = New Document(PageSize.A4, 1, 0, 0, 30)
PdfWriter.GetInstance(doc, New FileStream(Server.MapPath("path/filename.pdf"),FileMode.Create))
doc.AddAuthor("Author name")
doc.Open()
doc.NewPage()
Dim tablemain As Table = New Table(1)
'here table(1) denotes the 1 collumns, when u add the cell then it creates the one column and then 2nd cell is make the 2nd row for that column
tablemain.BorderWidth = 0
tablemain.Width = 100.0F
tablemain.Padding = 0
tablemain.Spacing = 0
Dim celln As New Cell(New Chunk(“string” & vbCrLf, labelFont14))
celln.Width = 90.0F
celln.HorizontalAlignment = Element.ALIGN_CENTER
tablemain.AddCell(celln)
doc.Add(tablemain)
doc.Close()
as per your requirements you can set the collumns and rows
This entry was posted on July 8, 2009 at 5:18 PM and is filed under ASP.NET. Tagged: Generating PDF in .NET using iTextSharp, iTextSharp and pdf file, Make a PDF file from asp.net, make PDF, PDF, pdf and asp.net. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.



Background Image in PDF File with ItextSharp in Asp.Net « Web Developer Friend said
[...] my past post http://viralsarvaiya.wordpress.com/2009/07/08/make-a-pdf-file-from-asp-net/ is demonstrate how to develop the pdf file, but when i search in web that have less example for the [...]