/// <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. 安装关系型数据库MySQL 安装大数据处理框架Hadoop

    作业要求来自:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE2/homework/3161 1.Hadoop的介绍 Hadoop最早起源于Nutch.Nut ...

  2. Win10电脑桌面壁纸自动变成黑色无法更换怎么解决

    很多用户在升级到win10之后,发现在使用过程中经常会碰到一些问题,就是电脑桌面壁纸总是会自动变成黑色,而且无法设置桌面背景壁纸,这是怎么回事呢,出现这样的问题可能是因为系统不是正版,或者是电脑设置不 ...

  3. 电商ERP系统——商品SKU与库存设计

    面试题经常问道,如何设计库存,哪些库存呢?分类属性的库存:不同颜色 不同尺码的属性的库存,这时候需要针对具体的SKU商品创建表. 总体思路 1.商品关联商品类别,商品类别关联多个商品属性,其中指定某几 ...

  4. ssh密匙互信操作【原创】

    1.简便ssh密匙信任方法 只在一台服务器上创建ssh-keygen [root@SMSJKSRVBJ02 ~]# ssh-keygen Generating public/private rsa k ...

  5. Python selenium PO By.XPATH定位元素报错

    Python selenium PO  By.XPATH定位元素报错 如下代码经常报错: # 首页的“新建投放计划”按钮 new_ads_plan = (By.XPATH, "//*[tex ...

  6. qemu-img convert -c disk /var/lib/nova/instances/_base/94a107318b54108fc8e76fff21a86d7c390a20bf -O qcow2 hebin.qcow2

  7. C#使用SHA1加密类(RSAFromPkcs8)支持1024位和2048位私钥

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...

  8. Java基础 三目运算符 用if-else对其进行解释

        JDK :OpenJDK-11      OS :CentOS 7.6.1810      IDE :Eclipse 2019‑03 typesetting :Markdown   code ...

  9. Android 加密之文件级加密(CE/DE)

    https://blog.csdn.net/myfriend0/article/details/77094890/   Android加密之文件级加密

  10. python读取yaml文件,在unittest中使用

    python读取yaml文件使用,有两种方式: 1.使用ddt读取 2,使用方法读取ddt的内容,在使用方法中进行调用 1.使用ddt读取 @ddt.ddt class loginTestPage(u ...