/// <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. Eclipse安装jbpm插件

    1.1   eclipse mar 和neon有什么区别? Eclipse 是一个开放源代码的.基于Java的可扩展开发平台.就其本身而言,它只是一个框架和一组服务,用于通过插件组件构建开发环境. . ...

  2. Clion下同时编写多个main函数

    在你的CMakeLists.txt文件下配置,使用add_executable(),前面的一定要不一样 红色部分是描述main的,配置后运行处可以选择:

  3. ngxtop安装和使用

    监控nginx的请求信息,总共收到了多少个请求,有哪些成功的,有哪些失败的 ngxtop安装 1.安装python-pip 1) yum install epel-release 出现如下错误:No ...

  4. jmeter cookie管理器

    jmeter cookie管理器 不能用正则表达式获取登录接口生成的cookie 因为cookies并不是在登录的响应结果中生成的,而是在response header中携带的,所以不能用正则表达式提 ...

  5. EMQ 与 mqtt 与 IOT设备

    1.IOT设备的特性 IOT(物联网things of internet)设备和传统的智能设备有什么区别,笔者总结下的IOT设备有如下特点: 硬件能力差(存储能力基本只有几MB,CPU频率低连使用HT ...

  6. Activiti task claim concurrent

    Activiti task claim cocurrent - 国内版 Binghttps://cn.bing.com/search?q=Activiti+task+claim+cocurrent&a ...

  7. webconfig 配置 分离

    https://blog.csdn.net/zhifeiya/article/details/38828711 如标题,如何把 asp.net webconfig的appSettings分离到单独文件 ...

  8. iostat vmstat

    iostat https://linux.die.net/man/1/iostat https://www.geeksforgeeks.org/iostat-command-in-linux-with ...

  9. 【Ubuntu升级python3.5到python3.6】dpkg-deb: error: subprocess paste was killed by signal (Broken pipe) Errors were encountered while processing: E: Sub-process /usr/bin/dpkg returned an error code (1) 问题解决

    Ubuntu16.04上将系统自带的python3.5升级到3.6 安装aioredis时提示Python版本需>=3.5.3,所以进行升级命令如下: $ sudo add-apt-reposi ...

  10. c的指针和php中的引用的区别

    https://blog.csdn.net/yangfanzn/article/details/44731391 1-php和c中的变量名都会被解析成内存地址,变量名所代表的内存的地址中内容即代表变量 ...