拿别人例子

  public ActionResult index()
{ var ms = new MemoryStream();
#region CreatePDF
Document document = new Document(PageSize.A4, 5f, 5f, 30f, 0f);
//Document document = new Document(PageSize.A4.Rotate(), 0f, 0f, 10f, 0f);(A4纸横线打印)
PdfWriter writer = PdfWriter.GetInstance(document, ms);
document.Open(); PdfPTable table = new PdfPTable();
table.TotalWidth = ;
table.LockedWidth = true;
table.SetWidths(new int[] { , , , , , , , });
PdfPCell cell;
BaseFont bfChinese = BaseFont.CreateFont("C://WINDOWS//Fonts//simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
iTextSharp.text.Font fontChinese_11 = new iTextSharp.text.Font(bfChinese, , iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(, , ));
iTextSharp.text.Font fontChinese_10 = new iTextSharp.text.Font(bfChinese, , iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(, , ));
iTextSharp.text.Font fontChinese_bold = new iTextSharp.text.Font(bfChinese, , iTextSharp.text.Font.BOLD, new iTextSharp.text.BaseColor(, , ));
iTextSharp.text.Font fontChinese_8 = new iTextSharp.text.Font(bfChinese, , iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(, , ));
iTextSharp.text.Font fontChinese = new iTextSharp.text.Font(bfChinese, , iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(, , ));
//黑体
BaseFont bf_ht = BaseFont.CreateFont("C://WINDOWS//Fonts//simhei.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
iTextSharp.text.Font ht_7 = new iTextSharp.text.Font(bf_ht, , iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(, , )); cell = new PdfPCell(new Phrase("钻石小鸟", fontChinese_11));
cell.Colspan = ;
cell.HorizontalAlignment = Element.ALIGN_CENTER;
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
cell.Border = Rectangle.NO_BORDER;
table.AddCell(cell); cell = new PdfPCell(new Phrase("定金单", fontChinese_10));
cell.Colspan = ;
cell.HorizontalAlignment = Element.ALIGN_CENTER;
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
cell.Border = Rectangle.NO_BORDER;
table.AddCell(cell); cell = new PdfPCell(new Phrase(" ", fontChinese));
cell.Colspan = ;
cell.HorizontalAlignment = Element.ALIGN_LEFT;
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
cell.Border = Rectangle.NO_BORDER;
table.AddCell(cell); cell = new PdfPCell(new Phrase(" ", fontChinese));
cell.Colspan = ;
cell.HorizontalAlignment = Element.ALIGN_LEFT;
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
cell.Border = Rectangle.NO_BORDER;
table.AddCell(cell); string str = "客户: 电话:卡号";
cell = new PdfPCell(new Phrase(str, fontChinese));
cell.Colspan = ;
cell.HorizontalAlignment = Element.ALIGN_LEFT;
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
cell.Border = Rectangle.NO_BORDER;
cell.Padding = ;
cell.PaddingLeft = ;
table.AddCell(cell);
str = "出货:";
cell = new PdfPCell(new Phrase(str, fontChinese));
cell.Colspan = ;
cell.HorizontalAlignment = Element.ALIGN_RIGHT;
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
cell.Border = Rectangle.NO_BORDER;
cell.Padding = ;
table.AddCell(cell); document.Add(table); table = new PdfPTable();
table.TotalWidth = ;
table.LockedWidth = true;
table.SetWidths(new int[] { , , , , , , , }); cell = new PdfPCell(new Phrase("条码\n单内ID", fontChinese_bold));
cell.HorizontalAlignment = Element.ALIGN_CENTER;
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
cell.Padding = ;
table.AddCell(cell); cell = new PdfPCell(new Phrase("名称\n款号(镶口范围)", fontChinese_bold));
cell.HorizontalAlignment = Element.ALIGN_CENTER;
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
cell.Padding = ;
table.AddCell(cell); cell = new PdfPCell(new Phrase("证书", fontChinese_bold));
cell.HorizontalAlignment = Element.ALIGN_CENTER;
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
cell.Padding = ;
table.AddCell(cell); cell = new PdfPCell(new Phrase("重量", fontChinese_bold));
cell.HorizontalAlignment = Element.ALIGN_CENTER;
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
cell.Padding = ;
table.AddCell(cell); cell = new PdfPCell(new Phrase("参数", fontChinese_bold));
cell.HorizontalAlignment = Element.ALIGN_CENTER;
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
cell.Padding = ;
table.AddCell(cell); cell = new PdfPCell(new Phrase("原价\n成品价", fontChinese_bold));
cell.HorizontalAlignment = Element.ALIGN_CENTER;
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
cell.Padding = ;
table.AddCell(cell); cell = new PdfPCell(new Phrase("优惠", fontChinese_bold));
cell.HorizontalAlignment = Element.ALIGN_CENTER;
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
cell.Padding = ;
table.AddCell(cell); cell = new PdfPCell(new Phrase("单内备注", fontChinese_bold));
cell.HorizontalAlignment = Element.ALIGN_CENTER;
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
cell.Padding = ;
table.AddCell(cell);
decimal total_osaled_earnest = 0M;
//特殊通用条码List cell = new PdfPCell(new Phrase(" ", fontChinese));
cell.Colspan = ;
cell.Padding = ;
table.AddCell(cell); cell = new PdfPCell(new Phrase(" ", fontChinese));
cell.Padding = ;
table.AddCell(cell); //同一行文字设置不同的字体样式
Phrase phrase = new Phrase();
phrase.Add(new Chunk(" 实收金额(大写):", fontChinese));
phrase.Add(new Chunk(" 我自己写的文字 ", fontChinese));
cell = new PdfPCell(phrase);
cell.Colspan = ;
cell.HorizontalAlignment = Element.ALIGN_LEFT;
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
cell.Padding = ;
table.AddCell(cell); cell = new PdfPCell(new Phrase(total_osaled_earnest.ToString("#0.00"), fontChinese));
cell.HorizontalAlignment = Element.ALIGN_CENTER;
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
table.AddCell(cell); cell = new PdfPCell(new Phrase(" ", fontChinese));
cell.Colspan = ;
cell.HorizontalAlignment = Element.ALIGN_LEFT;
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
cell.Border = Rectangle.NO_BORDER;
table.AddCell(cell); str = "客户须知\n\n";
str += "1、定金单作为取货的重要凭证,请妥善保管。结单时,请同时携带定单及定单人身份证件方可取货。\n\n";
str += "2、定单有效期30天,请于定金单显示的出货日期起30天内结单。如未能按时结单,则视为合同自动解除,产品将不再保留;所付定金将视为违约金,不予返还。\n\n";
str += "3、请核对定单内容后签字确认,定制类定单在定金支付完成后流转到工厂定制,定制期间无法再更改定单内容。产品出货后如非质量问题,定单不予退换。\n\n";
str += "4、如过出货日期仍未收到我们的到货通知,请尽快联系我们的客服中心4008800051,查询定单具体情况。\n";
cell = new PdfPCell(new Phrase(str, ht_7));
cell.Colspan = ;
cell.HorizontalAlignment = Element.ALIGN_LEFT;
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
cell.Border = Rectangle.NO_BORDER;
table.AddCell(cell); cell = new PdfPCell(new Phrase(" ", fontChinese));
cell.Border = Rectangle.NO_BORDER;
table.AddCell(cell); str = " 客服电话:400-880-0051\n\n";
str += " 专业钻石网站:www.zbird.com";
cell = new PdfPCell(new Phrase(str, fontChinese));
//cell.Colspan = 2;
cell.HorizontalAlignment = Element.ALIGN_LEFT;
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
cell.Border = Rectangle.NO_BORDER;
table.AddCell(cell); cell = new PdfPCell(new Phrase(" ", fontChinese));
cell.Colspan = ;
cell.HorizontalAlignment = Element.ALIGN_LEFT;
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
cell.Border = Rectangle.NO_BORDER;
table.AddCell(cell); string SalesEmployeeNo = "";
if (!string.IsNullOrWhiteSpace(SalesEmployeeNo))
{
SalesEmployeeNo = SalesEmployeeNo.TrimEnd();
}
string orecev_maker_employeeno = "";
if (!string.IsNullOrWhiteSpace("ddddd"))
{
orecev_maker_employeeno = "asdfsadfsafa";
}
else
{
orecev_maker_employeeno = SalesEmployeeNo;
}
str = @"营业员:" + SalesEmployeeNo + " 收银员:" + orecev_maker_employeeno + " 销售(签字):______________ 顾客(签字):______________";
cell = new PdfPCell(new Phrase(str, fontChinese));
cell.Colspan = ;
cell.HorizontalAlignment = Element.ALIGN_LEFT;
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
cell.Border = Rectangle.NO_BORDER;
table.AddCell(cell); str = @"★号代表刻爱心符号";
cell = new PdfPCell(new Phrase(str, fontChinese));
cell.Colspan = ;
cell.HorizontalAlignment = Element.ALIGN_RIGHT;
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
cell.Border = Rectangle.NO_BORDER;
table.AddCell(cell); cell = new PdfPCell(new Phrase(" ", fontChinese));
cell.Colspan = ;
cell.HorizontalAlignment = Element.ALIGN_LEFT;
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
cell.Border = Rectangle.NO_BORDER;
table.AddCell(cell); document.Add(table); table = new PdfPTable();
table.TotalWidth = ;
table.LockedWidth = true; cell = new PdfPCell(new Phrase("", fontChinese));
cell.Colspan = ;
cell.Border = Rectangle.NO_BORDER;
table.AddCell(cell);
//插入Logo图
string imagePath = Server.MapPath("~/Content/images/0.jpeg");
iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(imagePath);
cell = new PdfPCell(image, true);
cell.Colspan = ;
cell.HorizontalAlignment = Element.ALIGN_RIGHT;
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
cell.Border = Rectangle.NO_BORDER;
table.AddCell(cell);
document.Add(table); //iTextSharp.text.Rectangle pageSize = document.PageSize;
//document.SetPageSize(pageSize);
document.NewPage();
document.Close();
#endregion
//System.IO.File.Delete(filePath); return File(ms.ToArray(), "application/pdf","1.pdf");
}

2、还有一种方法,也不错,可以查看 下面连接

https://www.cnblogs.com/red-fox/p/5632718.html

.Net iTextSharp 生成pdf的更多相关文章

  1. itextsharp生成pdf后的直接打印问题

    原文 itextsharp生成pdf后的直接打印问题 小弟这两天用itextsharp生成pdf文档,生成的pdf可以直接保存在指定路径的文件夹下,可是user不想保存,想要点一下button,就可以 ...

  2. iTextSharp生成PDF文件

    这是一篇简单的教程,所以只涉及一些iTextSharp生成pdf的简单应用,详细教程请搜索iTextSharp进入官网看官方文档(英文版). iTextSharp官方文档:https://itextp ...

  3. iTextSharp生成pdf的一个简单例子

    效果图: 参考:http://www.cnblogs.com/CareySon/archive/2011/11/09/2243496.html http://www.cnblogs.com/julyl ...

  4. C#使用itextsharp生成PDF文件

    项目需求需要生成一个PDF文档,使用的是VS2010,ASP.NET. 网络上多次搜索没有自己想要的,于是硬着头皮到itextpdf官网看英文文档,按时完成任务,以实用为主,共享一下: 使用HTML文 ...

  5. iTextSharp生成pdf含模板(二)---C#代码部分

    参考地址:https://www.cnblogs.com/ibeisha/p/itextsharp-pdf.html 一.先在程序中使用Nuget安装iTextSharp(我是创建的控制台程序) 二. ...

  6. iTextSharp生成pdf文档案例

    1.using iTextSharp.text;using iTextSharp.text.pdf; 2.设置页面大小 iTextSharp.text.Rectangle pageSize = new ...

  7. 利用ItextSharp 生成PDF文档改进版

    导入的ItextSharp.dll一定要是较高的版本 数据库表结构 生成的PDF样式 代码: namespace WebPDF { public partial class _Default : Sy ...

  8. itextsharp生成pdf

    itextsharp在ios中可用,亲测 (一)生成文档 Document document = , , , ), , , , ); //Document document = new Documen ...

  9. C# iTextSharp 生成 PDF

    使用iTextSharp在Asp.Net中操作PDF系列文章 目录 http://www.cnblogs.com/CareySon/category/332146.html 实战 iTextSharp ...

随机推荐

  1. 新建一个Java Web程序

    依次选择 File——New——Web——Dynamic Web Project 输入项目名称“MyWebProject”,选择好Apache Tomcat V9.0服务器,其他采用默认配置. 单击N ...

  2. RESTful简介

    一.RESTful是什么? RESTful架构,就是目前最流行的一种互联网软件架构.它结构清晰.符合标准.易于理解.扩展方便,所以正得到越来越多网站的采用.Fielding将他对互联网软件的架构原则, ...

  3. @Helper辅助方法和@functions自定义函数

    1.首先说下@helper辅助方法,当我们在多个视图中共用相同的方法的时候,可以把此方法剥离出来放到一个位置,此时就可以用到@Helper辅助方法,首先我们在解决方案右键添加 App_Code文件夹, ...

  4. 用vs2012编译cocos2dx-3.9

    这几天想玩一下cocos2dx3.9新版本的东西,但是公司电脑配置不够,开个vs2012都卡的不行,更别提高版本的了.因为cocos2dx-3.9中使用了好多c++11的规范,而vs2012有好多C+ ...

  5. 【日常训练】数据中心(CSP 201812-4)

    分析 题目实际上是在要在给定的边上构建出一个树,使得这个树的最长边尽可能小. 这实际上是最小生成树的性质(反证法).问题从而得到解决. 代码 /* * Code name => csp20181 ...

  6. Qt-网易云音乐界面实现-2 红红的程序运行图标,和相似下方音乐条

    被调出来出差了,这次出差可以说是非常不开心,这次出差也算给我自己提了个醒吧,那就是注意自己的精力,自己的口碑,和比人对自己的信任.具体内容如下 我们公司有一款硬件的设备的电路是外包给某个人来做的,这个 ...

  7. [Processing] 弹球

    PVector localPos = new PVector(0,0);//起始位置 PVector velocity;//速度方向 float speed = 20;//速度大小 void setu ...

  8. oracle数据库数据字典应用

    oracle数据字典 数据字典是由oracle服务器创建和维护的一组只读的系统表.数据字典分为两类:一是基表,二是数据字典视图. 数据字典视图包括用户名.用户权限.对象名.约束和审计等信息,是通过运行 ...

  9. mysql删除表中的记录

    大家都知道,在MySQL中删除一个表中的记录有两种方法,一种是DELETE FROM TABLENAME WHERE... , 还有一种是TRUNCATE TABLE TABLENAME. DELET ...

  10. 某简单易懂的人脸识别 API 的开发环境搭建和简易教程

    最近接了个人脸识别相关的项目,是基于某个非常简单易懂的人脸识别 API:face_recognition 做的.这个库接口非常傻瓜,很适合新手上手,而且可以研究其源码来学习 dlib 这个拥有更加灵活 ...