(C#) ASP.NET Pdf Multiple Page |
(C#) ASP.NET Pdf Multiple Page ตัวอย่างการเขียน ASP.NET กับ PDF สร้างเอกสารหลาย ๆ หน้า
Language Code : VB.NET || C#
ASP.NET Add Reference
Framework : 1,2,3,4
Instance NameSpace
VB.NETImports PdfSharp
C#Using PdfSharp;
AspNetPDFAddPage.aspx
<%@ Import Namespace="PdfSharp"%>
<%@ Import Namespace="PdfSharp.Drawing"%>
<%@ Import Namespace="PdfSharp.Pdf"%>
<%@ Import Namespace="PdfSharp.Pdf.IO"%>
<%@ Page Language="C#" Debug="true" %>
<script runat="server">
void Page_Load(Object sender, EventArgs e)
{
// Create a new PDF document
PdfDocument DocPDF = new PdfDocument();
// Create an empty page
PdfPage objPage = DocPDF.AddPage();
// Get an XGraphics object for drawing
XGraphics gfx = XGraphics.FromPdfPage(objPage);
// Create a font
XFont font1 = new XFont("Verdana", 20, XFontStyle.Bold);
XFont font2 = new XFont("Tahoma", 8, XFontStyle.Bold);
// Draw the text
gfx.DrawString(" Welcome To www.ThaiCreate.Com", font1, XBrushes.Black,
new XRect(0, 50, objPage.Width.Point, objPage.Height.Point), XStringFormats.TopCenter);
String strString = "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...
String FileName = "MyPDF/PdfDoc.pdf";
DocPDF.Save(Server.MapPath(FileName));
DocPDF.Close();
DocPDF = null;
this.lblText.Text = "PDF Created <a href=" + FileName + ">click here</a> to view";
}
</script>
<html>
<head>
<title>ThaiCreate.Com ASP.NET - Send Mail</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Label id="lblText" runat="server"></asp:Label>
</form>
</body>
</html>
Screenshot
|