web 2.0

ASP.NET(vb.net) & Pdf Multiple Page

ASP.NET(vb.net) & Pdf Multiple Page - This article explains and example how to create PDF documents and add new create multiples page.

ShotDev Focus:
- ASP.NET(vb.net) & Pdf Multiple Page

Example

AspNetPDFAddPage.aspx

<%@ Import Namespace="PdfSharp"%>
<%@ Import Namespace="PdfSharp.Drawing"%>
<%@ Import Namespace="PdfSharp.Pdf"%>
<%@ Import Namespace="PdfSharp.Pdf.IO"%>
<%@ Page Language="VB" %>
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)

' Create a new PDF document
Dim DocPDF As PdfDocument = New PdfDocument

' Create an empty page
Dim objPage As PdfPage = DocPDF.AddPage

' Get an XGraphics object for drawing
Dim gfx As XGraphics = XGraphics.FromPdfPage(objPage)

' Create a font
Dim font1 As XFont = New XFont("Verdana", 20, XFontStyle.Bold)
Dim font2 As XFont = New XFont("Tahoma", 8, XFontStyle.Bold)

' Draw the text
gfx.DrawString(" Welcome To www.ShotDev.Com", font1, XBrushes.Black, _
New XRect(0, 50, objPage.Width.Point, objPage.Height.Point), XStringFormats.TopCenter)

Dim strString As String = "STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING"
' Draw the text
gfx.DrawString(strString, font2, XBrushes.Black, 65, 80, XStringFormats.TopLeft)
' Draw the text
gfx.DrawString(strString, font2, XBrushes.Black, 65, 90, XStringFormats.TopLeft)

'*** Page 2 ***'
objPage = DocPDF.AddPage()
gfx = XGraphics.FromPdfPage(objPage)
gfx.DrawString(strString, font2, XBrushes.Black, 65, 80, XStringFormats.TopLeft)
gfx.DrawString(strString, font2, XBrushes.Black, 65, 90, XStringFormats.TopLeft)

'*** Page 3 ***'
objPage = DocPDF.AddPage()
gfx = XGraphics.FromPdfPage(objPage)
gfx.DrawString(strString, font2, XBrushes.Black, 65, 80, XStringFormats.TopLeft)
gfx.DrawString(strString, font2, XBrushes.Black, 65, 90, XStringFormats.TopLeft)

' Save the document...
Dim FileName As String = "MyPDF/PdfDoc.pdf"
DocPDF.Save(Server.MapPath(FileName))

DocPDF.Close()
DocPDF = Nothing

Me.lblText.Text = "PDF Created <a href=" & FileName & ">click here</a> to view"

End Sub

</script>
<html>
<head>
<title>ShotDev.Com Tutorial</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Label id="lblText" runat="server"></asp:Label>
</form>
</body>
</html>

Screenshot

ASP.NET(vb.net) & Pdf Multiple Page

ASP.NET(vb.net) & Pdf Multiple Page

ASP.NET(vb.net) & Pdf Multiple Page
.
.
.
Download this script.
Download

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (No Ratings Yet)
Loading ... Loading ...

Leave a Reply

You must be logged in to post a comment.