/// <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. GoCN每日新闻(2019-10-23)

    GoCN每日新闻(2019-10-23) GoCN每日新闻(2019-10-23) 1. 从0开始,用Go实现Lexer和Parser https://mp.weixin.qq.com/s/cFGJX ...

  2. P1099 树网的核——模拟+树形结构

    P1099 树网的核 无根树,在直径上找到一条长度不超过s的路径,使得最远的点距离这条路径的距离最短: 首先两遍dfs找到直径(第二次找的时候一定要吧father[]清零) 在找到的直径下枚举长度不超 ...

  3. 集合类 collection接口 ArrayList

    数组: 存储同一种数据类型的集合容器.数组的特点:1. 只能存储同一种数据类型的数据.2. 一旦初始化,长度固定. 3. 数组中的元素与元素之间的内存地址是连续的. : Object类型的数组可以存储 ...

  4. socket http tcp ip 区别联系

    功能是实现继承复用.刚才做了一个简要的概述,里面有一些常用的概念,这里做个简短的概念普及介绍:(1),TCP/IP------TPC/IP协议是传输层协议,主要解决数据如何在网络中传输.(2),Soc ...

  5. 论文解读:3D Hand Shape and Pose Estimation from a Singl RGB Image

    本文链接:https://blog.csdn.net/williamyi96/article/details/89207640由于最近做到了一些 3D Hand Pose Estimation 相关的 ...

  6. electron---表单验证问题

    使用elementui进行表单提交数据的时候,经常会需要用到表单验证的功能,下面就来说说这个功能. <template> <div> <el-form :model=&q ...

  7. servlet的session的生命周期

    谈到javaweb首先想到的就是servlet,说道servlet就会想到servlet的生命周期 说道servlet的生命周期 就绕不过servlet的三个方法init service destro ...

  8. Java的方法类型

    1.无参数无返回值的方法 package com.imooc.method; public class MethodDemo { public static void printStar() { Sy ...

  9. python中urllib的urlencode与urldecode

    当url地址含有中文,或者参数有中文的时候,这个算是很正常了,但是把这样的url作为参数传递的时候(最常见的callback),需要把一些中文甚至'/'做一下编码转换. urlencode urlli ...

  10. 【技术】Arduino PID自整定库

    最近看到了Brett Beauregard发表的有关PID的系列文章,感觉对于理解PID算法很有帮助,于是将系列文章翻译过来!在自我提高的过程中,也希望对同道中人有所帮助.作者Brett Beaure ...