.net 生成pdf表格
只需要建一个类文件就搞定了
public class CreatePDF
{
public static CreatePDF Current { get { return new CreatePDF(); } }
public void CreatePDFs(RBS.Models.UserConfirmModel Model)
{
Document document = new Document();
string filepath = "/Upload/Pdf/";
Directory.CreateDirectory(HttpContext.Current.Server.MapPath(filepath));
PdfWriter.GetInstance(document, new FileStream(HttpContext.Current.Server.MapPath(filepath + "001.pdf"), FileMode.Create));
document.Open();
BaseFont bftitle = BaseFont.CreateFont(@"C:\\Windows\Fonts\SIMHEI.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
Font fonttitle = new Font(bftitle, , Font.UNDERLINE);
BaseFont bf1 = BaseFont.CreateFont(@"C:\\Windows\Fonts\SIMSUN.TTC,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
Font font1 = new Font(bf1, );
Font fonttitle10 = new Font(bf1, );
Font fonttitle12 = new Font(bf1, );
PdfPCell cellmode = new PdfPCell(); cellmode.Padding = ;
Paragraph Title = new Paragraph("信息总表", fonttitle);
Title.SetAlignment("center");
document.Add(Title);
PdfPTable topTable = new PdfPTable();
PdfPCell topCell = new PdfPCell();
topCell.PaddingTop = 10F;
topCell.Colspan = ;
topCell.Border = ;
topTable.AddCell(topCell);
document.Add(topTable);
PdfPTable table = new PdfPTable();
CreateCell(, false, "广州XXXXXX公司", fonttitle10, "left", table);
CreateCell(, false, "字第190898765号", fonttitle10, "right", table);
CreateCell(, , , "兹批准 广州市XXXXXXX分公司 去购买下列物品", fonttitle10, "center", table);
CreateCell(, true, "物品名称", fonttitle10, "center", table);
CreateCell(, true, "数量", fonttitle10, "center", table);
CreateCell(, true, "备注", fonttitle10, "center", table);
string[] arrNames = { "物品名称1", " 物品名称2", " ", " " };
string[] arrCounts = { "10吨", "800公斤", "", "" };
for (int i = ; i < arrNames.Length; i++)
{
CreateCell(, , , arrNames[i], fonttitle10, "center", table);
CreateCell(, , , arrCounts[i], fonttitle10, "center", table);
CreateCell(, , , " ", fonttitle10, "center", table);
}
CreateCell(, false, " 此证由填发日起止2013年03月19日有效 逾期作废", fonttitle10, "left", table);
CreateCell(, false, " 到本县、市以外购买物品时,必须经出售地政府机关在备注栏内盖章后方能有效", fonttitle10, "left", table);
CreateCell(, , , " \r填发人:XXX", fonttitle10, "left", table);
CreateCell(, false, "广东省广州市\r\n2013年3月5日", fonttitle10, "right", table); document.Add(table);
document.Close();
} ///
/// 生成单元格
///
/// 合并列数
/// 是否需要边框线
/// 表格内显示的内容
/// 内容字体
/// 对齐方式
/// 此单元格填充的表
private void CreateCell(int Colspan, bool Border, string Content, Font font, string alignment, PdfPTable table)
{
if (Border)
CreateCell(Colspan, , , Content, font, alignment, table);
else
CreateCell(Colspan, , Content, font, alignment, table);
}
///
/// 生成单元格
///
/// 合并列数
/// 间距
/// 内容
/// 字体
/// 对齐方式
/// 此单元格填充的表
private void CreateCell(int Colspan, int Padding, string Content, Font font, string alignment, PdfPTable table)
{
CreateCell(Colspan, Padding, , Content, font, alignment, table);
}
///
/// 生成单元格
///
/// 合并列数
/// 间距
/// 边框线
/// 内容
/// 字体
/// 对齐方式
/// 此单元格填充的表
private void CreateCell(int Colspan, int Padding, int Border, string Content, Font font, string alignment, PdfPTable table)
{
CreateCell(Colspan, Padding, Border, , , Content, font, alignment, table);
}
///
/// 生成单元格
///
/// 合并列数
/// 间距
/// 边框线
/// 水平对齐方式
/// 垂直对齐方式
/// 内容
/// 字体
/// 对齐方式
/// 此单元格填充的表
private void CreateCell(int Colspan, int Padding, int Border, int HorizontalAlignment, int VerticalAlignment, string Content, Font font, string alignment, PdfPTable table)
{
PdfPCell cell = new PdfPCell();
cell.Colspan = Colspan;
cell.Padding = Padding;
if (HorizontalAlignment > )
cell.HorizontalAlignment = HorizontalAlignment;
if (VerticalAlignment > )
cell.VerticalAlignment = VerticalAlignment;
if (Border == )
cell.Border = Border;
Paragraph table_t = new Paragraph(Content, font);
table_t.SetAlignment(alignment);
cell.AddElement(table_t);
table.AddCell(cell);
} }
.net 生成pdf表格的更多相关文章
- MVC 生成PDf表格并插入图片
最近做的项目中有一个功能,将最终的个人信息生成PDF表格,并插入图片.对于没接触过的程序员来说回一片茫然,网上有多种生成PDf的方法,我给大家介绍一下我认为比较简单,好操作的一种. iTextShar ...
- Java 生成pdf表格文档
最近在工作做一个泰国的项目,应供应商要求,需要将每天的交易生成pdf格式的报表上传到供应商的服务器,特此记录实现方法.废话不多说,直接上代码: THSarabunNew.ttf该文件是泰国字体自行网上 ...
- java使用iText生成pdf表格
转载地址:http://www.open-open.com/code/view/1424011530749 首先需要你自己下载itext相关的jar包并添加引用,或者在maven中添加如下引用配置: ...
- java(itext) 一个很简单的PDF表格生成工具
先上个效果图 因为做的项目涉及到数据预测,其中有大量打印业务来支撑实体店的运营,因为注重的是数据,要求简洁,清晰,所以写了个很简单也很实用的工具类. 如果需要编写样式或者插入背景,都可以查阅itex官 ...
- iText生成PDF 格式报表
1.导包 <dependency> <groupId>com.lowagie</groupId> <artifactId>itext</artif ...
- 【Java】itext根据模板生成pdf(包括图片和表格)
1.导入需要的jar包:itext-asian-5.2.0.jar itextpdf-5.5.11.jar. 2.新建word文档,创建模板,将文件另存为pdf,并用Adobe Acrobat DC打 ...
- iTextSharp生成pdf的一个简单例子
效果图: 参考:http://www.cnblogs.com/CareySon/archive/2011/11/09/2243496.html http://www.cnblogs.com/julyl ...
- 用js生成PDF的方案
在java里,我们常用Itext来生成pdf,在pdf文件里组合图片,文字,画表格,画线等操作,还会遇到中文支持的问题. 那好,现在想直接在web前端就生成pdf怎么办,目前有以下几个解决方案 1:J ...
- 【Java】使用iText生成PDF文件
iText介绍 iText是著名的开放源码的站点sourceforge一个项目,是用于生成PDF文档的一个java类库.通过iText不仅可以生成PDF或rtf的文档,而且可以将XML.Html文件转 ...
随机推荐
- 消息队列数量统计(MSMQ,Performance Counter)
微软消息队列服务MSMQ (Microsoft Message Queue),工作在在线或者离线场景,并提供异步编程功能.互联网和企业开发很多场景应用,例如电商的订单处理流程,这是因为客户端不需要等待 ...
- Oracle- 数据库的备份
Oracle中对数据对象和数据的管理,无疑都是使用PL/SQL Developer来进行管理,该工具也提供给我们很多方便.快捷的操作,使得我们不再为Oracle本身丑陋.难用的UI而抱怨.由于我们一般 ...
- Fox-H 函数
1.定义 2.特例 3.在分数阶微分方程中的应用 4.如何画图
- ALV可输入状态下输入金额字段变小数的问题
http://blog.163.com/mxb_sap@yeah/blog/static/10335262520167109022155/ 小数位数两位 当我在给ALV上给该字段输入整数 '12 ...
- ZZTHX-线程锁
以前一直在做卡乐付,悲剧的是项目中的余额查询,超级转账和刷卡器相关的东西已经开发好了,我对这块还是比较好奇和感兴趣的,在项目空闲的时候我就开始尝试熟悉和了解这块的业务和代码.实践出真理,只有在实践中才 ...
- spring mvc处理json
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...
- 【不积跬步,无以致千里】Linux下启动Oracle服务和监听程序
oracle数据库是重量级的,其管理非常复杂,将其在linux平台上的启动和关闭步骤整理一下. 安装完毕oracle以后,需要创建oracle系统用户,并在/home/oracle下面的.bash_p ...
- Http协议网络对时工具
2009-09-17 11:52:31 专业的网络对时软件大多採用NTP协议来获取专业时间server时间对时,也有採用SNTP协议的,本来也想做个SNTP或NTP协议的对时工具自己用,尽管我手上也有 ...
- Codeforces Beta Round #96 (Div. 1) D. Constants in the language of Shakespeare 贪心
D. Constants in the language of Shakespeare Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codef ...
- Fragment的使用简单介绍【Android】
Fragment在实际项目开发中使用的越来越多,如今简介一下 布局文件: <LinearLayout xmlns:android="http://schemas.android.com ...