List<LableFileResponse> data = new List<LableFileResponse>();for (var i = 0; i < listServerCode.Count; i++){if (listServerCode == null || listServerCode.Count == 0){return new LabelResponse(){success = 0,cnmessage = "未获取到标签信息" +"",enmessage = "Not get the label information"};}WebHeaderCollection we = new WebHeaderCollection();we.Add("ClientKey", ClientKey);we.Add("ClientSecret", ClientSecret);string strResult = Utils.HttpPost(strUrl, "orderNumber=" + listShipperCode[0], we);Lable upsresult = JsonHelper.JSONToObject<Lable>(strResult);List<string> urlList = new List<string>();//生成pdf 文件地址string pdf_file_path = string.Format("/api-lable/pdf/{0}/", DateTime.Now.ToString("yyyyMMdd"));string pdf_file_name_pdf = string.Format("{0}.pdf", System.Guid.NewGuid().ToString());string pdf_output_filepath = System.Web.HttpContext.Current.Server.MapPath("~" + pdf_file_path);string strLabelSavePath = pdf_output_filepath + pdf_file_name_pdf;string strDirectory = Path.GetDirectoryName(strLabelSavePath);if (!Directory.Exists(strDirectory)){Directory.CreateDirectory(strDirectory);}byte[] bytes = Convert.FromBase64String(upsresult.data.image);System.IO.FileStream stream =new FileStream(strLabelSavePath, FileMode.CreateNew);System.IO.BinaryWriter writer =new BinaryWriter(stream);writer.Write(bytes, 0, bytes.Length);writer.Close();png图片转pdf//var document = new Document(iTextSharp.text.PageSize.A4, 25, 25, 25, 25);//using (var stream = new FileStream(strLabelSavePath, FileMode.Create, FileAccess.Write, FileShare.None))//{//    PdfWriter.GetInstance(document, stream);//    document.Open();//    using (var imageStream = new FileStream(pngPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))//    {//        var image = iTextSharp.text.Image.GetInstance(imageStream);//        if (image.Height > iTextSharp.text.PageSize.A4.Height - 25)//        {//            image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);//        }//        else if (image.Width > iTextSharp.text.PageSize.A4.Width - 25)//        {//            image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);//        }//        image.Alignment = iTextSharp.text.Image.ALIGN_MIDDLE;//        document.NewPage();//        document.Add(image);//    }//    document.Close();//}urlList.Add(strLabelSavePath);string lable_file = string.Empty;//多个合成一个pdf的地址string filename_pdf = string.Format("{0}.pdf", System.Guid.NewGuid().ToString());string file_path_pdf = string.Format("/api-lable/pdf/{0}/", DateTime.Now.ToString("yyyyMMdd"));string output_filepath_pdf = System.Web.HttpContext.Current.Server.MapPath("~" + file_path_pdf);string strLabelSavePathPdf = output_filepath_pdf + filename_pdf; //file_path + filename;// using (FileStream targetStream = new FileStream(strLabelSavePathPdf, FileMode.Create, FileAccess.Write, FileShare.None)){targetStream.Close();}PDFHeper.MergePages(strLabelSavePathPdf, urlList.ToArray());List<string> logistics_codes = new List<string>();logistics_codes.Add(listServerCode[0]);lable_file = "http://" + DTRequest.GetCurrentFullHost() + file_path_pdf + filename_pdf;LableFileResponse datas = new LableFileResponse() { lable_file_type = LabelPrintConst.FILE_TYPE_2, lable_file = lable_file, logistics_codes = logistics_codes };data.Add(datas);}if (data.Count > 1){List<string> sti = new List<string>();for (var i = 0; i < data.Count; i++){sti.Add(data[i].lable_file);}string pdf_file_path1 = string.Format("/api-lable/pdf/{0}/", DateTime.Now.ToString("yyyyMMdd"));string pdf_file_name1 = string.Format("{0}.pdf", System.Guid.NewGuid().ToString());string labelUrl1 = "~" + pdf_file_path1 + pdf_file_name1;labelUrl1 = pdf_file_path1 + pdf_file_name1;//PDFHeper.MergePDFFiles(sti, labelUrl);labelUrl1 = System.Web.HttpContext.Current.Server.MapPath("~" + labelUrl1);//sti.Add(labelUrl1);PDFHeper.MergePages(labelUrl1, sti.ToArray());labelUrl1 = "http://" + DTRequest.GetCurrentFullHost() + pdf_file_path1 + pdf_file_name1;return new LabelResponse() { success = 1, data = new List<LableFileResponse>() { new LableFileResponse() { lable_file_type = LabelPrintConst.FILE_TYPE_2, lable_file = labelUrl1 } } };}else if (data.Count == 1){return new LabelResponse() { success = 1, data = data };}public static void MergePages(string outputPdfPath, string[] lstFiles){PdfReader reader = null;Document sourceDocument = null;PdfCopy pdfCopyProvider = null;PdfImportedPage importedPage;sourceDocument = new Document();pdfCopyProvider = new PdfCopy(sourceDocument,new System.IO.FileStream(outputPdfPath, System.IO.FileMode.Create));sourceDocument.Open();try{foreach (string item in lstFiles){reader = new PdfReader(item);int pages = reader.NumberOfPages;//Add pages of current filefor (int i = 1; i <= pages; i++){importedPage = pdfCopyProvider.GetImportedPage(reader, i);pdfCopyProvider.AddPage(importedPage);}reader.Close();}sourceDocument.Close();}catch (Exception ex){throw ex;}}

pdf电脑地址转网络地址.txt相关推荐

  1. 主机地址、网络地址、主机路由、网络路由

    主机地址: 主机地址,就是指某一台电脑的Ip地址,如:192.168.1.10 网络地址: 就是指某一段ip地址,比如:192.168.1.0 这个就是c类网络地址,192.168.1.0 为一段,1 ...

  2. PDF怎么批量转换成TXT格式?

    现在大部分人都有阅读电子书的习惯,通常电子书的文件格式都是TXT文件形式,TXT文件是微软在操作系统上附带的一种最常见文本格式,它体积小.存储简单方便,所以我们通常会使用这种格式文档.有时候我们在网上 ...

  3. 传奇世界服务器端口被占用,Windows socket error: 通常每个套接字地址(协议/网络地址/端口)只允许使用一次。 (10048), on API 'bi...

    Windows socket error: 通常每个套接字地址(协议/网络地址/端口)只允许使用一次. (10048), on API 'bind' 你们的系统80%都是XP的,这个就是XP系统的不适 ...

  4. 前端学习(1856)vue之电商管理系统电商系统之安装mysql出现mysql报错:Can’t start server: Bind on TCP/IP port: 通常每个套接字地址(协议/网络地址

    2020-07-26T11:44:29.778919Z 0 [ERROR] [MY-010262] [Server] Can't start server: Bind on TCP/IP port: ...

  5. 如何把PDF文档转换成TXT格式文件

    在日常学习和日常工作中,如何将PDF文件转换为TXT文本? 尽管PDF文件的用户数量正在增加,但是TXT文本格式的接受度将会更高. 毕竟,TXT文本格式是任何设备都可以打开的格式.那么如何将PDF文件 ...

  6. OSError: [WinError 10048] 通常每个套接字地址(协议/网络地址/端口)只允许使用一次。

    OSError: [WinError 10048] 通常每个套接字地址(协议/网络地址/端口)只允许使用一次. import socket s = socket.socket(socket.AF_IN ...

  7. 日语900句(衣食住行)PDF下载地址|百度云盘免费分享

    有人说,金字塔的魅力就在于它完美的建筑结构,有坚实深厚的基础,才造就了塔尖的辉煌. 学好日语也是同样的道理,坚实的语言基础很多时候来源于大量的输入,量变达到质变,这种语言便能脱口而出,语感" ...

  8. 计算机网络 王道考研2021 第四章:网络层 -- lPv4地址、私有IP地址、网络地址转换 (NAT)、WAN / LAN

    文章目录 1. lPv4地址 1.1 IP地址 1.2 IP编址的历史阶段 1.3 分类的IP地址 1.4 互联网中的IP地址 1.5 特殊lP地址:不能作为主机或者路由器的具体接口标识 1.6 私有 ...

  9. vue实战--vue+elementUI实现多文件上传+预览(word/PDF/图片/docx/doc/xlxs/txt)

    需求 最近在做vue2.0+element UI的项目中遇到了一个需求:需求是多个文件上传的同时实现文件的在线预览功能.需求图如下: 看到这个需求的时候,小栗脑袋一炸.并不知道该如何下手,之前的实践项 ...

最新文章

  1. [Oracle11g] 通过伪列查询
  2. 设计模式之-简单工厂模式
  3. 过年不回家,压岁钱、份子钱省下来了吗?
  4. Eclipse添加git插件上传项目到github
  5. iis ftp服务器文件大小,iis ftp服务器文件大小
  6. unity velocity_Unity动画系统详解5:BlendTree混合树是什么?
  7. Linux入门-网络实验3.3
  8. 数据结构入门指南(C语言版)
  9. 拉普拉斯变换的matlab仿真,拉普拉斯变换及Simulink仿真.doc
  10. 【转】姚班学霸陈立杰
  11. Gradle简要教程
  12. 在Pycharm中,全文搜索、替换,以及单独文件搜索、替换!
  13. python 华为交换机自动配置_对python连接华为交换机批量配置优化
  14. SAP-MM科目自动分配解析-(4-1)- 物料的配置影响
  15. 201771010137 赵栋《面向对象程序设计(java)》第十八周学习总结
  16. CSS生成关闭叉叉图标
  17. 微博粉丝精灵_王晓晨微博粉丝破千万 走心独白致谢陪伴
  18. 解决Ubuntu虚拟机NAT不能上网的几种方法
  19. 最小二乘拟合 matlab 初值的选取,最小二乘拟合法
  20. OpenCv--Mat矩阵(图像容器)的创建及CV_8UC1,CV_8UC2等参数详解

热门文章

  1. CCF201312-4 有趣的数(100分)
  2. 生成式模型(generative) vs 判别式模型(discriminative)
  3. 广义逆高斯分布(Generalized Inverse Gaussian Distribution)及修正贝塞尔函数
  4. 数论基本定理及应用(四)
  5. matlab 格式化输出
  6. C++基础::自制异常定位器
  7. java adt简单开发,android java开发 第一天 之熟悉eclipse adt-Go语言中文社区
  8. python有什么用-python有什么用
  9. 免费python自学攻略-自学python二三事
  10. python语言的主网址-怎么用Python提取域名中的主域名