itextsharp c# asp.net 生成 pdf 文件
一切的开始必须要有2个dll, 可以通过nuget 包xiazai, 关键字是itextsharp.
using iTextSharp.text;
using iTextSharp.text.pdf;
FileStream fs = new FileStream(Server.MapPath("pdf") + "\\" + "First PDF document6.pdf", FileMode.Create); //done
Document document = new Document(PageSize.A4, , , , );
PdfWriter writer = PdfWriter.GetInstance(document, fs);
document.AddAuthor("Micke Blomquist");
document.AddCreator("Sample application using iTextSharp");
document.AddKeywords("PDF tutorial education");
document.AddSubject("Document subject - Describing the steps creating a PDF document");
document.AddTitle("The document title - PDF creation using iTextSharp");
document.Open();
document.Add(new Paragraph(""));
以上就可以简单的在文档中找到Doc1.pdf 了,现在会记入简单的css样式。
Font arial = FontFactory.GetFont("Arial", , Font.BOLD, BaseColor.RED);//字体 Chunk c1 = new Chunk("A chunk represents an isolated string.", arial);
c1.SetUnderline(0.5f, -1.5f);//下划线 document.Add(c1);
chunk是可以赋予很多的style,目前我只需要下划线和基本的字体,颜色。接下来是table
PdfPTable table = new PdfPTable(); //列 table.TotalWidth = 216f; //table width
table.LockedWidth = true; //配合table width float[] widths = new float[] { 3f, 2f }; //table 的行比列
table.SetWidths(widths);
table.SpacingBefore = 10f; //margin-top
table.SpacingAfter = 30f; //margin-bottom
table.HorizontalAlignment = ; //0=Left, 1=Centre, 2=Right (float)
PdfPCell cell = new PdfPCell(new Phrase("content"));
//cell.Colspan = 1; //列
cell.HorizontalAlignment = ; //0=Left, 1=Centre, 2=Right (text)
cell.Padding = ;
//cell.Border = 1;
table.AddCell(cell);
table.AddCell(cell);
table.AddCell(cell);
table.AddCell(cell);
table.AddCell(cell);
table.AddCell(cell); document.Add(table);
table设计的是像html的float,首先给table知道几列,以上是2列,所以所有的cell都是左右左右的排列。最后是图片
document.Add(new Paragraph("JPG"));
iTextSharp.text.Image gif = iTextSharp.text.Image.GetInstance(Server.MapPath("123.jpg"));
document.Add(gif);
完成了,这就是基本功了!
http://www.mikesdotnetting.com/article/80/create-pdfs-in-asp-net-getting-started-with-itextsharp
itextsharp c# asp.net 生成 pdf 文件的更多相关文章
- asp.net生成PDF文件 (1)
asp.net生成PDF文件 (1) 这个是例子是网上淘来的,哈哈,很有用的! 首先要到网上下载itextsharp.dll,然后添加引用,主程序如下: 1 2 3 4 5 6 7 8 9 10 11 ...
- asp.net MVC设计模式中使用iTextSharp实现html字符串生成PDF文件
因个人需求,需要将html格式转换成PDF并加上水印图片.于是乎第一次接触这种需求的小菜鸟博主我,在某度搜索引擎上不断的查阅关键字资料.踩坑,终于有了一个相应的解决方案.以下是解决步骤,记录下来方便以 ...
- asp.net生成PDF文件参考 .
TextSharp 是用来生成 PDF 的一个组件,在 1998 年夏天的时候,Bruno Lowagie ,iText 的创作者,参与了学校的一个项目,当时使用 HTML 来生成报告,但是,使用 ...
- asp.net生成PDF文件(一)
这个是例子是网上淘来的,哈哈,很有用的! 首先要到网上下载itextsharp.dll,然后添加引用,主程序如下: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1 ...
- 根据PDF模板生成PDF文件(基于iTextSharp)
根据PDF模板生成PDF文件,这里主要借助iTextSharp工具来完成.场景是这样的,假如要做一个电子协议,用过通过在线填写表单数据,然后系统根据用户填写的数据,生成电子档的协议.原理很简单,但是每 ...
- 在C#.NET中,如何生成PDF文件?主要有以下几个途径
1.使用.NET文件流技术:若通过.NET的文件流技术生成PDF文件,必须对PDF文件的语法很清楚,例如BT表示实体内容开始:ET表示实体内容结束:TD表示换行等等.我们可以从Adobe的官方网站上下 ...
- asp.net 生成PDF方法
今天转博客园看到有人发表了一篇生成PFd的文章,准备自己也留一份准备以后用到的时候方便调用: 首先去itextsharp网站下载控件(https://sourceforge.net/projects/ ...
- C#生成PDF文件流
1.设置字体 static BaseFont FontBase = BaseFont.CreateFont("C:\\WINDOWS\\FONTS\\STSONG.TTF", Ba ...
- linux下编译bib、tex生成pdf文件
实验: 在linux环境下,编译(英文)*.bib和*.tex文件,生成pdf文件. 环境: fedora 20(uname -a : Linux localhost.localdomain 3.19 ...
随机推荐
- iOS MVVM 前世今生
MVVM,Model-View-ViewModel,一个从 MVC 模式中进化而来的设计模式,最早于2005年被微软的 WPF 和 Silverlight 的架构师 John Gossman 提出.
- Python3基础 nonlocal关键字 内部函数访问到外部函数的变量
镇场诗: 诚听如来语,顿舍世间名与利.愿做地藏徒,广演是经阎浮提. 愿尽吾所学,成就一良心博客.愿诸后来人,重现智慧清净体.-------------------------------------- ...
- grunt安装详解及失败处理
标签: 1.官网 nodejs官网 https://nodejs.org/en/ Grunt官网 http://gruntjs.com/ Grunt插件首页 http://gruntjs.com/p ...
- iOS 项目上线流程
一.证书的导出 1.1 前期工作 首先你需要有一个苹果的开发者帐号,一个Mac系统. 如果没有帐号可以在打开http://developer.apple.com/ ...
- --@angularJS--浅谈class与Ng-Class的应用
1.angularjs的表达式是可以写在class里面动态改变其值的,写法如下: □.CSS1.html: <!doctype html><html ng-app="MyC ...
- HTML模块化:使用HTML5 Boilerplate模板
HTML5 Boilerplate 是一个由 Paul Irish(Google Chrome 开发人员.jQuery 项目成员.Modernizr 作者.yayQuery 播客主持人)主导的“前端开 ...
- java解析XML,并生成文档
一.Java中XML的四种方法 Java学习者须知:Java中XML的四种方法 java xml学习总结(4中方法的例子介绍) JDOM解析XML Dom4j解析XML
- Raphael初始化,path,circle,rect,ellipse,image
path jsp: <%@ page language="java" contentType="text/html; charset=UTF-8" pag ...
- iReport默认参数和变量的含义解析【转】
iReport默认参数和变量的含义解析[转] http://uule.iteye.com/blog/775338 参考:http://blog.csdn.net/terryzero/article/d ...
- flex 事件注册和鼠标拖动
flex 事件注册和鼠标拖动 <?xml version="1.0" encoding="utf-8"?> <s:Application xm ...