All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
网页申请表单用户体验设计简述_[Html教程]
用sql存储过程实现前台标题变色_[SQL Server教程]
Linux系统上把PHP编译进Apache静态内核_php资料_编程技术
据库的主键与外键--转载_mssql学习_编程技术
SQL,Server:错误18483_[SQL,Server教程]
用VS.NET,2005重构你的代码_[Asp.Net教程]
asp.net中Server对象的应用实例
delphi中使用sql server触发器实例
单击GridView某行获取该行某列内容并显示_[Asp.Net教程]
SQL触发器实例_mssql学习_编程技术
Reading number is top 10 pictures
Group of female porn in 《westwards》, uninhibited woman threatened to not the bottom line1
全身蕾丝丝质美臀
Perfect small Laurie1
谁认识这位校花
Average female college students3
In the world the most mysterious 21 place landscape1
西游日记4
BingBingFan apple dew point photo gallery4
yy365网站上的美女1
The money of more than 100 countries and regions15
Download software ranking
Macromedia Dreamweaver 8
Rio big adventure
Be there or be square
C#编程思想
Sora aoi‘s film--Lust fan wall
asp.net技术内幕
徐若瑄成名作“魔鬼天使”
Tram sex maniac 2 (H) rar bag7
Call Of Duty2
Unix video tutorial9
delv published in(发表于) 2014/1/24 9:03:57 Edit(编辑)
asp.net2.0导出pdf文件完美解决方案_[Asp.Net教程]

asp.net2.0导出pdf文件完美解决方案_[Asp.Net教程]

asp.net2.0导出pdf文件完美解决方案_[Asp.Net教程]

PDF简介:PDF(Portable Document Format)文件格式是Adobe公司开发的电子文件格式。这种文件格式与操作系统平台无关,也就是说,PDF文件不管是在Windows,Unix还是在苹果公司的Mac OS操作系统中都是通用的。这一特点使它成为在Internet上进行电子文档发行和数字化信息传播的理想文档格式。越来越多的电子图书、产品说明、公司文告、网络资料、电子邮件开始使用PDF格式文件。PDF格式文件目前已成为数字化信息事实上的一个工业标准。


Adobe公司设计PDF文件格式的目的是为了支持跨平台上的,多媒体集成的信息出版和发布,尤其是提供对网络信息发布的支持。为了达到此目的, PDF具有许多其他电子文档格式无法相比的优点。PDF文件格式可以将文字、字型、格式、颜色及独立于设备和分辨率的图形图像等封装在一个文件中。该格式文件还可以包含超文本链接、声音和动态影像等电子信息,支持特长文件,集成度和安全可靠性都较高。


日常工作中经常遇到想把报表和网页导出到PDF的需求。本文提供完美的解决方案:


ASP.NET导出到PDF的最终效果图(其实winform和控制台程序都一样可以做)。


本文实现 文字,图片,数据表的导出
核心技术方案:使用itextsharp.dll


1.下载itextsharp.dll和ICSharpCode.SharpZipLib.dll
http://sourceforge.net/project/showfiles.php?group_id=72954



onclick="window.location='/project/downloading.php?group_id=72954&use_mirror=nchc&filename=iTextSharp.tutorial.01.zip&'+Math.floor(Math.random()*100000000); return false;" href="http://downloads.sourceforge.net/itextsharp/iTextSharp.tutorial.01.zip?modtime=1129139556&big_mirror=0">iTextSharp.tutorial.01.zip 示例文件 提供了各种解决方案本文由于时间问题仅做抛砖引玉,希望大家自己研究其他需求


itextsharp.dll onclick="window.location='/project/downloading.php?group_id=72954&use_mirror=nchc&filename=itextsharp-4.0.3-dll.zip&'+Math.floor(Math.random()*100000000); return false;" href="http://downloads.sourceforge.net/itextsharp/itextsharp-4.0.3-dll.zip?modtime=1176738754&big_mirror=0">itextsharp-4.0.3-dll.zip


ICSharpCode.SharpZipLib.dll http://download.csdn.net/down/135897 ICSharpCode.SharpZipLib.dll


SharpZipLib.dll类库中的内容实现的压缩与解压功能,它是开源的


2.引用itextsharp.dll和ICSharpCode.SharpZipLib.dll



3.后台代码:


using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using iTextSharp;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
static DataTable datatable = new DataTable("testpdf");
protected void Page_Load(object sender, EventArgs e)
{
//判断是否是回发页面http://blog.csdn.net/21aspnet
if (!Page.IsPostBack)
{
DataRow dr;
//建立Column例,可以指明例的类型,这里用的是默认的string
datatable.Columns.Add(new DataColumn("编号"));
datatable.Columns.Add(new DataColumn("用户名"));
for (int i = 1; i < 5; i++)
{
dr = datatable.NewRow();
dr[0] = System.Convert.ToString(i);
dr[1] = "清清月儿" + System.Convert.ToString(i);
datatable.Rows.Add(dr);
}
}


}
protected void Button1_Click(object sender, EventArgs e)
{


try
{
Document document = new Document();
PdfWriter.getInstance(document, new FileStream(Server.MapPath("Chap0101.pdf"), FileMode.Create));
document.Open();
BaseFont bfChinese = BaseFont.createFont("C:\\WINDOWS\\Fonts\\simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
Font fontChinese = new Font(bfChinese, 12, Font.NORMAL,new Color(0, 0, 0));


document.Add(new Paragraph(this.TextBox1.Text.ToString(), fontChinese));


iTextSharp.text.Image jpeg = iTextSharp.text.Image.getInstance(Server.MapPath("pic015.jpg"));
document.Add(jpeg);
PdfPTable table = new PdfPTable(datatable.Columns.Count);


for (int i = 0; i < datatable.Rows.Count; i++)
{
for (int j = 0; j < datatable.Columns.Count; j++)
{
table.addCell(new Phrase(datatable.Rows[i][j].ToString(), fontChinese));
}
}
document.Add(table);


document.Close();
}
catch (DocumentException de)
{;
Response.Write(de.ToString());
}
}
}


4.前台代码:



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>





清清月儿 制作导出PDF http://blog.csdn.net/21aspnet






onClick="Button1_Click" Text="导出" />





5.前台操作:


6.属性说明:


onclick="window.location='/project/downloading.php?group_id=72954&use_mirror=nchc&filename=itextsharp-4.0.3-dll.zip&'+Math.floor(Math.random()*100000000); return false;" href="http://downloads.sourceforge.net/itextsharp/itextsharp-4.0.3-dll.zip?modtime=1176738754&big_mirror=0">itextsharp-4.0.3-dll.zip 示例文件包含几乎所有的PDF处理需求


颜色:
Font fontChinese = new Font(bfChinese, 12, Font.NORMAL,new Color(0, 0, 0)); //黑Font fontChinese = new Font(bfChinese, 12, Font.NORMAL,new Color(0, 255, 0)); //绿


注释:

iText支持不同风格的注释。

u 文本注释:

你可以添加一小段文本到你的文档中,但它并非文档内容的一部分,注释有标题和内容:

Annotation a = new Annotation(

"authors",

"Maybe it's because I wanted to be an author myself that I wrote iText.");


对齐方式:
cell.HorizontalAlignment = Element.ALIGN_CENTER;

cell.VerticalAlignment = Element.ALIGN_MIDDLE;


下划线/删除线:
Chunk chunk1 = new Chunk("This text is underlined", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.UNDERLINE));

Chunk chunk2 = new Chunk("This font is of type ITALIC | STRIKETHRU", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.ITALIC | Font.STRIKETHRU));


加密:
public void setEncryption(boolean strength, String userPassword, String ownerPassword, int permissions);


由于时间问题:更多如页眉页脚属性目录水印单元格间距边框等等请大家自己研究文档。


你想得到的想不到的示例文件都有。

作者:清清月儿







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.