c#记录合并PDF和word

 使用 Aspose.Words合并word

using Aspose.Words;

  string CombineWord(string id, params string[] pages)//合并模板doc
     {
         string path1 = "", path2 = "", path3 = "", path4 = "";
         string[] tpls = { "商品混凝土出厂合格证", "开盘检定", "生产任务通知单", "生产用混凝土配合比调整通知单" };
         path1 = GetTplPath(tpls[0],out path1);
         path2 = GetTplPath(tpls[1], out path2);
         path3 = GetTplPath(tpls[2], out path2);
         path4 = GetTplPath(tpls[3], out path4);
         if (string.IsNullOrEmpty(path1))
         {
             CommanFunction.WriteLog2("printHeBing.log", "合并打印," + tpls[0] + "的模板不存在");
             return null;
         }
         else if (string.IsNullOrEmpty(path2))
         {
             CommanFunction.WriteLog2("printHeBing.log", "合并打印," + tpls[1] + "的模板不存在");
             return null;
         }
         else if (string.IsNullOrEmpty(path3))
         {
             CommanFunction.WriteLog2("printHeBing.log", "合并打印," + tpls[3] + "的模板不存在");
             return null;
         }
         else if (string.IsNullOrEmpty(path4))
         {
             CommanFunction.WriteLog2("printHeBing.log", "合并打印," + tpls[3] + "的模板不存在");
             return null;
         }
         else {
             path1 = Server.MapPath(path1);
             path2 = Server.MapPath(path2);
             path3 = Server.MapPath(path3);
             path4 = Server.MapPath(path4);
           var dstDoc = AppendDocument(new Document(path1), new Document(path2));
             dstDoc = AppendDocument(dstDoc, new Document(path3));
             dstDoc = AppendDocument(dstDoc, new Document(path4));
             var dir = Server.MapPath("/tempData");
             var savePath = Path.Combine(dir, id + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".doc");
             if (File.Exists(savePath))
                 File.Delete(savePath);
             dstDoc.Save(savePath);
             return savePath;
         }


     }

    Document AppendDocument(Document dstDoc, Document srcDoc, SectionStart sectionStart = SectionStart.NewPage)
     {
         srcDoc.FirstSection.PageSetup.SectionStart = sectionStart;
         dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting);
         ParagraphFormat pf = dstDoc.Styles.DefaultParagraphFormat;
         pf.ClearFormatting();
         return dstDoc;
     }

使用 Aspose.Pdf合并PDF

using Aspose.Pdf;
  string CombinePDF(string projectNum, params string[] pages)//合并模板
    {


        string path1 = "", path2 = "";
        if (pages.Length > 0)
        {
            path1 = Server.MapPath(pages[0]);
            CommanFunction.WriteLog2("printHeBing.log", "合并打印,CombinePDF,path1" + path1);
            Document pdfdoc1 = new Document(path1);
            for (int i = 1; i < pages.Length; i++)
            {
                path2 = Server.MapPath(pages[i]);
                Document pdfdoc2 = new Document(path2);
                pdfdoc1.Pages.Add(pdfdoc2.Pages);
            }

            var dir = Server.MapPath("/tempData");
            var savePath = Path.Combine(dir, projectNum + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".pdf");
            CommanFunction.WriteLog2("printHeBing.log", "合并打印,CombinePDF,savePath:" + savePath);
            if (File.Exists(savePath))
                File.Delete(savePath);
            pdfdoc1.Save(savePath);
            return savePath;
        }
        else
        {
            msg = "没有PDF可合并";
            return null;
        }



    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值