/// <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-02)

    GoCN每日新闻(2019-10-02) GoCN每日新闻(2019-10-02) 1. Golang中基于Gin和Casbin的web使用方式 https://dev.to/maxwellhertz ...

  2. 【00NOIP普及组】计算器的改良(信息学奥赛一本通 1910)(洛谷 1022)

    [题目描述] NCL是一家专门从事计算器改良与升级的实验室,最近该实验室收到了某公司所委托的一个任务:需要在该公司某型号的计算器上加上解一元一次方程的功能.实验室将这个任务交给了一个刚进入的新手ZL先 ...

  3. fillter根据value来匹配字段

    字段对应 let cashBackState = { 'WAIT_FIVE': '满5单可返现', 'FINISHED': '已返现' } filters: { cashBackStateFilter ...

  4. shell | crontab 定时任务

    crontab工具 linux下自带的定时任务执行器 常用命令:crontab -l //显示用户的crontab文件的内容crontab -e //编辑用户的crontab文件的内容crontab ...

  5. jquery数组倒序

    倒叙前:var mem = [1, 2, 3]: 倒序后:var men1=[3,2,1]: <script type="text/javascript"> $(fun ...

  6. [转]无法解析的外部符号 _main,该符号在函数 ___tmainCRTStartup 中被引用

    刚学WinAPI编译遇到不少问题,LNK2019: 无法解析的外部符号 _main,该符号在函数 ___tmainCRTStartup 中被引用 MSVCRTD.lib test. 这个问题表明你新建 ...

  7. 为什么用ls和du显示出来的文件大小有差别?【转】

    在使用Linux ls命令查看文件大小时,发现文件很大,足有100个G,而使用du命令查看则不超过10个G. [root@shanghai devicemapper]# ls -l 总用量 -rwxr ...

  8. Android ADB常用命令使用

    Android SDK: adb shell 命令的使用(am.pm.wm.screencap.monkey等) https://blog.csdn.net/xietansheng/article/d ...

  9. oracle系列九 SET运算符查询

    将多个查询用 SET 操作符连接组成一个新的查询 UNION/UNION ALL INTERSECT MINUS 排序:ORDER BY UNION 操作符 UNION 操作符返回两个查询的结果集的并 ...

  10. ISO/IEC 9899:2011 条款3——术语、定义与符号

    3. 术语.定义与符号 1.对于此国际标准的意图,应用了以下定义.其它术语是在用斜体类型或一个语法规则左侧出现的地方定义.在本国际标准中所显式定义的术语不被假定为对其它地方所定义的类似术语的隐式引用. ...