惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
博客园 - Franky
GbyAI
GbyAI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
博客园_首页
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recent Announcements
Recent Announcements
Scott Helme
Scott Helme
有赞技术团队
有赞技术团队
M
MIT News - Artificial intelligence
C
CERT Recently Published Vulnerability Notes
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Jina AI
Jina AI
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
L
LangChain Blog
L
LINUX DO - 最新话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
AI
AI
T
Troy Hunt's Blog
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
S
Secure Thoughts
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
S
Security @ Cisco Blogs
Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
Attack and Defense Labs
Attack and Defense Labs

博客园 - 三角猫

QQ vs 360的战争之我见 解决CHM文件的内容无法正常显示的问题 微软MSDN给出的使用.Net开发Windows Form网络应用相关程序的优化建议 Let’s Kill IE6 Firefox 火狐 3.6 正式发布 微软发布“极光”IE漏洞官方补丁 KB978207 MS10-002 保护SQL语句不被Sql Profiler / 事件探查器 捕获跟踪到 QQ2010Beta版体验申请已经开始,久违的通讯录功能终于恢复了 百度被黑事件的前世今生 之 三角猫篇 IIS+WordPress利用UrlRewrite实现永久链接(Permanent Links)的完美方案 利用Windows的命令行工具tasklist和findstr,start结合计划任务实现一种进程监控的方案 好久不用Delphi做开发,重拾Delphi7,生疏了很多啊 在VS2008的HTML设计器中,显示隐藏内容的一些标签 关闭WordPress上传图片时自动生成缩略图功能 Wordpress + IIS6 中文tag和中文地址的解决方案 美化Visual Studio代码编辑器的字体,使中文和英文使用不同的字体 Windows7和Vista系统中,像XP一样在桌面上显示出IE图标 WebForm_PostBackOptions 未定义/undefined WebResource.axd FreeTextBox Ajax回调压缩 C#读取注册表,获取本机安装的软件清单
.Net开源PDF类库 itextsharp 测试
三角猫 · 2010-01-09 · via 博客园 - 三角猫

Pdf,一个让人又爱又恨的文件格式,但是它的应用却真的是愈来愈广泛了。虽然,目前的Office 2007及后续的版本都已经支持Pdf格式了,但是,用微软的开发平台,目前来生成PDF文档的免费选择仍然十分少。

iTextSharp,是目前做的比较成熟的.net 平台下的开源项目,它的地址在 http://sourceforge.net/projects/itextsharp/

按照它的官方说明,是支持的非常广泛的,PDF、XML、图片等待都支持的。经过测试,发现它生成的pdf文件是 PDF1.4 的版本,就是 Acrobat Reader 5.x 的版本。

今天,为了生成PDF,找到这个类库,做了测试,结果令我大失所望。把测试结果发布出来,希望能和大家交流,也许是我自己没能正确使用它吧

生成的PDF文件,截图如下:

itextsharp pdf csharp c# asp.net

对PDF文件的属性设置,支持的倒是比较完美:

itextsharp pdf c# csharp asp.net

在上面的图中,大家可能看到了那句 not support chinese 了,哈哈,就是我测试的凄惨结果:文档内容不支持中文

下面是测试代码:

using iTextSharp.text;
using iTextSharp.text.pdf;

Document document = new Document();

try
{

    // step 2:
    // we create a writer that listens to the document
    // and directs a PDF-stream to a file

    PdfWriter.GetInstance(document, new FileStream("Chap0101.pdf", FileMode.OpenOrCreate));

    // step 3: we open the document
    document.Open();

    // step 4: we Add a paragraph to the document
    document.AddAuthor("三?角?猫?");
    document.AddCreationDate();
    document.AddCreator("DeltaCat");
    document.AddSubject("DotNet 使?用?itextsharp 类?库?创?建?PDF文?件?的?例?子?");
    document.AddTitle("此?PDF由?三?角?猫?创?建?,?嘿?嘿?");
    document.Add(new Paragraph("Hello World"));
    document.Add(new Paragraph("-------------------------------"));
    document.Add(new Paragraph(new Chunk("Not Support Chinese", new Font(5, 30, 2, new BaseColor(223)))));
}
catch(DocumentException de)
{
    Console.Error.WriteLine(de.Message);
}
catch(IOException ioe)
{
    Console.Error.WriteLine(ioe.Message);
}

// step 5: we close the document
document.Close();