Creating PDF documents in ASP.NET

" /> 在ASP.NET页面中创建PDF文档 - 技术笔记 - 岁月留声QtAsp

岁月留声QtAsp

Qt in Linux , Asp Asp.net Jsp Php in Web

« 两款可视编辑器,分别是FCKeditor和eWebEditor软件版本 总结 »

在ASP.NET页面中创建PDF文档

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:

Collapse Copy Code
Imports SystemImports System.IOImports iTextSharp.textImports iTextSharp.text.pdf

Next I decide in the Page_Load event which document was requested by the user:

Collapse Copy Code
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:

Collapse Copy Code
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

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

日历

Search

  •  

最新评论及回复

最近发表

Powered By Z-Blog 1.8 Spirit Build 80722 Code detection by Codefense

Copyright 2008-2011 京公网安备 110115000655 京ICP备09005635号 www.qtasp.cn WebSite. All Rights Reserved.