By fstrahberger
Creating PDF documents in ASP.NET
http://www.codeproject.com/KB/aspnet/Creating_PDF_documents_in.aspx
Introduction
This short article explains how to create PDF documents from ASP.NET web pages using the free library http://sourceforge.net/projects/itextsharp/.
简介
这篇很短的文章介绍如何在ASP.NET页面中创建PDF文档,本文使用了免费的开源库
首先,我会创建一个最简单的“Hello PDF”,接下来再使用table创建一个更复杂些的PDF文档。为了达到这些,你需要首先下载开源的itextsharp库(),并在项目中引用它。
更多内容见原文
PDF文档有页面ShowPDF.aspx创建,同时通过“Response.Redirect”传递PDF给用户。
First of all I create a simple "Hello PDF". Next I will create a more complex PDF document with tables. To start creating PDF documents you need to download the itextsharp library from http://sourceforge.net/projects/itextsharp/ and reference it in your project. The PDF documents are created "on the fly" by the web page "ShowPDF.aspx". This page does also a "Response.Redirect" to the created PDF. First import some required Namespaces:
Imports SystemImports System.IOImports iTextSharp.textImports iTextSharp.text.pdfNext I decide in the Page_Load event which document was requested by the user:
Partial Class ShowPDF Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Request.QueryString("id") = 1 Then ShowHello() Else ShowTable() End If End SubEnd Class
The ShowHello function creates the most simple document with just one string "Hello World" and the redirects the user to the newly created document:
Sub ShowHello() Dim doc As Document = New Document PdfWriter.GetInstance(doc, New FileStream(Request.PhysicalApplicationPath + "\1.pdf", FileMode.Create)) doc.Open() doc.Add(New Paragraph("Hello World")) doc.Close() Response.Redirect("~/1.pdf")End Sub