/// <summary>
/// 打印移库单
/// </summary>
/// <param name="guid"></param>
/// <returns></returns>
public OperationResult PrintHouseTrans(string guid)
{
OperationResult returnResult = new OperationResult(true);
var model = new House_Trans_HeadSaveDto();
model.HouseTransListSaveDtos = new List<House_Trans_ListSaveDto>();
if (!string.IsNullOrEmpty(guid))
{
House_Trans_Head entity = GetHouseTransHeadByGuid(guid);
model = entity.MapTo<House_Trans_HeadSaveDto, House_Trans_Head>(); var listDtos = GetListAndItemByHeadId(guid);
model.HouseTransListSaveDtos = listDtos;
}
if (model.HouseTransListSaveDtos.Any())
{
try
{
if (!Directory.Exists(HttpContext.Current.Server.MapPath(_printFilePath)))
{
Directory.CreateDirectory(HttpContext.Current.Server.MapPath(_printFilePath));
}
var newFileName = $"移库单-{DateTime.Now:yyyyMMddhhmmss}.pdf";
string filePath = $"{HttpContext.Current.Server.MapPath(_printFilePath)}{newFileName}"; Document docPDF = new Document(PageSize.A4, , , , );//创建一个pdf文档的对象,设置纸张大小为A4,页边距为0
//PageSize.A4.Rotate();当需要把PDF纸张设置为横向时,使用PageSize.A4.Rotate()
PdfWriter write = PdfWriter.GetInstance(docPDF, new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write));//创建一个写入PDF的对象,
BaseFont baseFont = BaseFont.CreateFont("C:\\Windows\\Fonts\\simkai.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
docPDF.Open();//打开 var table = new PdfPTable();
int[] TableWidths = { , , , , , , , , };
table.SetWidths(TableWidths);
table.TotalWidth = ;//设置绝对宽度
table.LockedWidth = true;//使绝对宽度模式生效 Image imgHead = Image.GetInstance(HttpContext.Current.Server.MapPath("/Content/Images/pdflogo.png"));
imgHead.Alignment = ;
PdfPCell cell_1_1 = new PdfPCell(imgHead);
cell_1_1.Border = Rectangle.NO_BORDER;
cell_1_1.MinimumHeight = ;
cell_1_1.Colspan = ;
table.AddCell(cell_1_1);
PdfPCell cell_1_2 = new PdfPCell(new Paragraph("移库任务清单", new Font(baseFont, , Font.BOLD)));
cell_1_2.PaddingLeft = ;
cell_1_2.Border = Rectangle.NO_BORDER;
cell_1_2.MinimumHeight = ;
cell_1_2.Colspan = ;
cell_1_2.VerticalAlignment = Element.ALIGN_MIDDLE;
table.AddCell(cell_1_2); PdfPCell cell_2_1 = new PdfPCell(new Paragraph($"客户:{model.CustomerNo}", new Font(baseFont, )));
cell_2_1.Border = Rectangle.NO_BORDER;
cell_2_1.MinimumHeight = ;
cell_2_1.VerticalAlignment = ;
table.AddCell(cell_2_1);
PdfPCell cell_2_2 = new PdfPCell();
cell_2_2.Border = Rectangle.NO_BORDER;
cell_2_2.MinimumHeight = ;
cell_2_2.Colspan = ;
cell_2_2.VerticalAlignment = Element.ALIGN_MIDDLE;
table.AddCell(cell_2_2); PdfPCell cell_3_1 = new PdfPCell(new Paragraph($"指令号:{model.CommandCode}", new Font(baseFont, )));
cell_3_1.Border = Rectangle.NO_BORDER;
cell_3_1.MinimumHeight = ;
cell_3_1.Colspan = ;
cell_3_1.VerticalAlignment = ;
table.AddCell(cell_3_1);
PdfPCell cell_3_2 = new PdfPCell(new Paragraph($"日期:{(model.DoTime != null ? ((DateTime)model.DoTime).ToString("yyyy-MM-dd") : "")}", new Font(baseFont, )));
cell_3_2.Border = Rectangle.NO_BORDER;
cell_3_2.MinimumHeight = ;
cell_3_2.Colspan = ;
cell_3_2.VerticalAlignment = Element.ALIGN_MIDDLE;
table.AddCell(cell_3_2); PdfPCell cell_4_1 = new PdfPCell(new Paragraph("序号", new Font(baseFont, , Font.BOLD)));
cell_4_1.MinimumHeight = ;
cell_4_1.VerticalAlignment = Element.ALIGN_MIDDLE;
cell_4_1.HorizontalAlignment = Element.ALIGN_CENTER;
table.AddCell(cell_4_1);
PdfPCell cell_4_2 = new PdfPCell(new Paragraph("产品代码\n品名", new Font(baseFont, , Font.BOLD)));
cell_4_2.MinimumHeight = ;
cell_4_2.VerticalAlignment = Element.ALIGN_MIDDLE;
cell_4_2.HorizontalAlignment = Element.ALIGN_CENTER;
table.AddCell(cell_4_2);
PdfPCell cell_4_3 = new PdfPCell(new Paragraph("包装\n单位", new Font(baseFont, , Font.BOLD)));
cell_4_3.MinimumHeight = ;
cell_4_3.VerticalAlignment = Element.ALIGN_MIDDLE;
cell_4_3.HorizontalAlignment = Element.ALIGN_CENTER;
table.AddCell(cell_4_3);
PdfPCell cell_4_4 = new PdfPCell(new Paragraph("原始库位\n目标库位", new Font(baseFont, , Font.BOLD)));
cell_4_4.MinimumHeight = ;
cell_4_4.VerticalAlignment = Element.ALIGN_MIDDLE;
cell_4_4.HorizontalAlignment = Element.ALIGN_CENTER;
table.AddCell(cell_4_4);
PdfPCell cell_4_5 = new PdfPCell(new Paragraph("原始属性\n目标属性", new Font(baseFont, , Font.BOLD)));
cell_4_5.MinimumHeight = ;
cell_4_5.VerticalAlignment = Element.ALIGN_MIDDLE;
cell_4_5.HorizontalAlignment = Element.ALIGN_CENTER;
table.AddCell(cell_4_5);
PdfPCell cell_4_6 = new PdfPCell(new Paragraph("库存数量\n转移数量", new Font(baseFont, , Font.BOLD)));
cell_4_6.MinimumHeight = ;
cell_4_6.VerticalAlignment = Element.ALIGN_MIDDLE;
cell_4_6.HorizontalAlignment = Element.ALIGN_CENTER;
table.AddCell(cell_4_6);
PdfPCell cell_4_7 = new PdfPCell(new Paragraph("批次号\n失效日期", new Font(baseFont, , Font.BOLD)));
cell_4_7.MinimumHeight = ;
cell_4_7.VerticalAlignment = Element.ALIGN_MIDDLE;
cell_4_7.HorizontalAlignment = Element.ALIGN_CENTER;
table.AddCell(cell_4_7);
PdfPCell cell_4_8 = new PdfPCell(new Paragraph("入库日期", new Font(baseFont, , Font.BOLD)));
cell_4_8.MinimumHeight = ;
cell_4_8.VerticalAlignment = Element.ALIGN_MIDDLE;
cell_4_8.HorizontalAlignment = Element.ALIGN_CENTER;
table.AddCell(cell_4_8);
PdfPCell cell_4_9 = new PdfPCell(new Paragraph("备注", new Font(baseFont, , Font.BOLD)));
cell_4_9.MinimumHeight = ;
cell_4_9.VerticalAlignment = Element.ALIGN_MIDDLE;
cell_4_9.HorizontalAlignment = Element.ALIGN_CENTER;
table.AddCell(cell_4_9); var startIndex = ;
foreach (var item in model.HouseTransListSaveDtos)
{
PdfPCell newclee_1 = new PdfPCell(new Paragraph(startIndex.ToString(), new Font(baseFont, )));
newclee_1.MinimumHeight = ;
newclee_1.VerticalAlignment = Element.ALIGN_MIDDLE;
newclee_1.HorizontalAlignment = Element.ALIGN_CENTER;
table.AddCell(newclee_1);
PdfPCell newclee_2 = new PdfPCell(new Paragraph($"{item.Sku}\n{item.GNameEn}", new Font(baseFont, )));
newclee_2.MinimumHeight = ;
newclee_2.VerticalAlignment = Element.ALIGN_MIDDLE;
newclee_2.HorizontalAlignment = Element.ALIGN_CENTER;
table.AddCell(newclee_2);
PdfPCell newclee_3 = new PdfPCell(new Paragraph($"{item.Unit}\n{item.Unit}", new Font(baseFont, )));
newclee_3.MinimumHeight = ;
newclee_3.VerticalAlignment = Element.ALIGN_MIDDLE;
newclee_3.HorizontalAlignment = Element.ALIGN_CENTER;
table.AddCell(newclee_3);
PdfPCell newclee_4 = new PdfPCell(new Paragraph($"{item.FromLocation}\n{item.ToLocation}", new Font(baseFont, )));
newclee_4.MinimumHeight = ;
newclee_4.VerticalAlignment = Element.ALIGN_MIDDLE;
newclee_4.HorizontalAlignment = Element.ALIGN_CENTER;
table.AddCell(newclee_4);
PdfPCell newclee_5 = new PdfPCell(new Paragraph($"{item.FromLocationAttribute}\n{item.ToLocationAttribute}", new Font(baseFont, )));
newclee_5.MinimumHeight = ;
newclee_5.VerticalAlignment = Element.ALIGN_MIDDLE;
newclee_5.HorizontalAlignment = Element.ALIGN_CENTER;
table.AddCell(newclee_5);
PdfPCell newclee_6 = new PdfPCell(new Paragraph($"{item.FromLeftQty}\n{item.FromLeftQty}", new Font(baseFont, )));
newclee_6.MinimumHeight = ;
newclee_6.VerticalAlignment = Element.ALIGN_MIDDLE;
newclee_6.HorizontalAlignment = Element.ALIGN_CENTER;
table.AddCell(newclee_6);
PdfPCell newclee_7 = new PdfPCell(new Paragraph($"{item.BatchNo}\n{item.ExpiryDate}", new Font(baseFont, )));
newclee_7.MinimumHeight = ;
newclee_7.VerticalAlignment = Element.ALIGN_MIDDLE;
newclee_7.HorizontalAlignment = Element.ALIGN_CENTER;
table.AddCell(newclee_7);
PdfPCell newclee_8 = new PdfPCell(new Paragraph($"{(model.DoTime != null ? ((DateTime)model.DoTime).ToString("yyyy-MM-dd") : "")}", new Font(baseFont, )));
newclee_8.MinimumHeight = ;
newclee_8.VerticalAlignment = Element.ALIGN_MIDDLE;
newclee_8.HorizontalAlignment = Element.ALIGN_CENTER;
table.AddCell(newclee_8);
PdfPCell newclee_9 = new PdfPCell(new Paragraph($"{model.Remark}", new Font(baseFont, )));
newclee_9.MinimumHeight = ;
newclee_9.VerticalAlignment = Element.ALIGN_MIDDLE;
newclee_9.HorizontalAlignment = Element.ALIGN_CENTER;
table.AddCell(newclee_9);
startIndex++;
} docPDF.Add(table);
docPDF.Close();//关闭
returnResult.Data = $"{_printFilePath}{newFileName}";
}
catch (Exception ex)
{
returnResult = new OperationResultFail("打印失败");
throw;
}
}
else
{
returnResult = new OperationResultFail("移库单下无数据");
}
return returnResult;
}

iTextSharp 不适用模板 代码拼接PDF的更多相关文章

  1. Itextsharp下根据Echarts图像生成pdf

    本文介绍如何在C#中使用ItextSharp生成带echarts图表的pdf 一.生成一个简单的pdf 后台代码 publicActionResultGetPdf() { MemoryStream m ...

  2. C# Net Core 使用 itextsharp.lgplv2.core 把Html转PDF

    C# Net Core 使用 itextsharp.lgplv2.core 把Html转PDF 只支持英文(中文我不知道怎么弄,懂的朋友帮我看一下)!!!!![补充:评论区的小伙伴已解决] 引入包it ...

  3. inputstream和outputstream读写数据模板代码

    //读写数据模板代码 byte buffer[] = new byte[1024]; int len=0; while((len=in.read(buffer))>0){ out.write(b ...

  4. eclipse 中 Servlet 模板代码(其实是代码提示模板)

    说的是模板代码,应该说的是提示的模板代码,并不是一新建就会出现模板. 第一步:先建一个Servlet文件,写好自己想要的模板 我的模板如下: 全选并复制,等会要粘贴到Servlet的提示模板中. pa ...

  5. 用Case类生成模板代码

    将类定义为case类会生成许多模板代码,好处在于: ①会生成一个apply方法,这样就可以不用new关键字创建新的实例. ②由于case类的构造函数参数默认是val,那么构造函数参数会自动生成访问方法 ...

  6. 【转】使用iTextSharp在Asp.Net中操作PDF

    使用iTextSharp在Asp.Net中操作PDF操作 使用iTextSharp在Asp.Net中操作PDF系列文章目录 实战 iTextSharp iTextSharp 合并多个PDF文件 C#生 ...

  7. django2用模板代码图标字体丢失报404 cJZKeOuBrn4kERxqtaUH3T8E0i7KZn-EPnyo3HZu7kw.woff

    以前开发网站,不是用php就是用c#或java写后端,跟后端繁重麻烦的代码相比,前端的html+css+JavaScript简直就简单的不算技术,相比之下,工作量也不大. 但如果用django框架,使 ...

  8. 2017/2/16:自己ajax+json习惯性写法 代码拼接的写法 +json用post提交乱码的原因

    1.先导入jquery的包 2.ajax的写法跟注意点 返回一个list的写法 代码拼接写法: html层: 2.script处 4:在你前面传递参数的时候没有遇到乱码问题的情况下,你使用json并且 ...

  9. 修改servlet的模板代码

    实际开发中,这些生成的代码和注释一般我们都用不到的,每次都要手工删除这些注释和代码,很麻烦.下面以MyEclipse 2014(其实版本通用的,都可以修改)为例进行说明如何修改Servlet的模板代码 ...

随机推荐

  1. 【04NOIP普及组】火星人(信息学奥赛一本通 1929)(洛谷 1088)

    [题目描述] 人类终于登上了火星的土地并且见到了神秘的火星人.人类和火星人都无法理解对方的语言,但是我们的科学家发明了一种用数字交流的方法.这种交流方法是这样的,首先,火星人把一个非常大的数字告诉人类 ...

  2. RocketMq重复消费问题排查

    前情 出现了重复消费的问题,同一个消息被重复消费了多次,导致了用户端收到了多条重复的消息,最终排查发现,是因为消费者在处理消息的方法onMessage中有异常没有捕获到,导致异常上抛,被consume ...

  3. 将linux上的网站代码托管到gogs git服务器上进行实时同步(实战)

    一.说明 本说明只针对php,其他语言需要编译请用别的架构实现 二.实现效果 本地开发员门提交推送代码到git服务器,会立即同步更新网站服务器上代码 三.实战步骤小节 首次托管请先看   https: ...

  4. 回顾idea快捷键

    F9            resume programe 恢复程序 Alt+F10       show execution point 显示执行断点 F8            Step Over ...

  5. Spring Boot方式的Dubbo项目

    项目依赖 需要org.apache.dubbo.dubbo-dependencies-bom, 需要org.apache.dubbo.dubbo-spring-boot-starter, 当前版本有2 ...

  6. typescript - 4.es5与typescript的类与继承

    ES5中的类与类的继承 (1)简单的类 function Person() { this.name = '张三'; this.age = 20; } var p = new Person(); ale ...

  7. meta name="location" 标签的使用

    在进行一些操作的时候,我们可能会用到这个标签来什么,地理位置,不错的网站优化标签. <meta name="location" content="province= ...

  8. 必须要注意的 C++ 动态内存资源管理(五)——智能指针陷阱

    必须要注意的 C++ 动态内存资源管理(五)——智能指针陷阱 十三.小心使用智能指针.         在前面几节已经很详细了介绍了智能指针适用方式.看起来,似乎智能指针很强大,能够很方便很安全的管理 ...

  9. python之psutil模块

    简述 psutil是一个跨平台库(http://code.google.com/p/psutil/) ,能够轻松实现获取系统运行的进程和系统利用率(包括CPU.内存.磁盘.网络等)信息.它主要应用于系 ...

  10. 删除Win10自动下载的更新安装包

    当我们禁止了系统的自动更新后,会感觉还有什么东西没做,没错,你还没有删除系统自动下载好的安装包,如果不删除的话会白白浪费磁盘空间!那么系统自动下载的安装包在哪里呢? C盘Windows—Softwar ...