当前位置: 首页 > news >正文

那个网站做外贸最好广州百度首页优化

那个网站做外贸最好,广州百度首页优化,东莞服装网站建设,用html5做的简单的网站一.开发框架: .NetCore6.0 工具:Visual Studio 2022 二.思路: 1.使用SHA256Hash标识文档转换记录,数据库已经存在对应散列值,则直接返还已经转换过的文档 2.数据库没有对应散列值记录的话,则保存上传PDF…

一.开发框架:

.NetCore6.0
工具:Visual Studio 2022

二.思路:

1.使用SHA256Hash标识文档转换记录,数据库已经存在对应散列值,则直接返还已经转换过的文档
2.数据库没有对应散列值记录的话,则保存上传PDF文档,并进行文档转换,保留Word
3.转换成功,则在数据库记录对应文档的转换记录,用散列值做标识

三.C#后台包:

1.方法一:Spire.PDF转换包(免费的只能一次转换10页)
在这里插入图片描述
2.方法二:iTextSharp包,没有10页转换限制
在这里插入图片描述
3.mssql数据库连接包
在这里插入图片描述
4.iTextSharp包转换Word文档时,文档格式包
在这里插入图片描述

四:C#代码案例:

1.PDF转Word方法:
a.方法一:Spire.PDF包,PDF转Word方法(旧版,有页码限制):

	 /// <summary>/// PDF文件转化为Word文件/// </summary>/// <param name="pdfFilePath"></param>/// <param name="wordFilePath"></param>public static void ConvertPdfToWord(string pdfFilePath, string wordFilePath){try{Spire.Pdf.PdfDocument pdfDoc = new Spire.Pdf.PdfDocument();pdfDoc.LoadFromFile(pdfFilePath);pdfDoc.SaveToFile(wordFilePath, Spire.Pdf.FileFormat.DOCX);pdfDoc.Close();}catch (Exception ex){Console.WriteLine("Error converting PDF to Word: " + ex.Message);}}

b.iTextSharp包,没有页码限制:

	 /// <summary>/// iTextSharp库PDF文件转Word文件/// </summary>/// <param name="pdfFilePath"></param>/// <param name="wordFilePath"></param>public static void ConvertPdfToWordByText(string pdfFilePath, string wordFilePath){using (iText.Kernel.Pdf.PdfReader reader = new iText.Kernel.Pdf.PdfReader(pdfFilePath)){using (iText.Kernel.Pdf.PdfDocument pdfDoc = new iText.Kernel.Pdf.PdfDocument(reader)){Spire.Doc.Document doc = new Spire.Doc.Document();for (int i = 1; i <= pdfDoc.GetNumberOfPages(); i++){iText.Kernel.Pdf.PdfPage page = pdfDoc.GetPage(i);var strategy = new iText.Kernel.Pdf.Canvas.Parser.Listener.LocationTextExtractionStrategy();PdfCanvasProcessor parser = new PdfCanvasProcessor(strategy);parser.ProcessPageContent(page);string textFromPage = strategy.GetResultantText();var paragraph = doc.AddSection().AddParagraph();paragraph.AppendText(textFromPage);}doc.SaveToFile(wordFilePath, Spire.Doc.FileFormat.Docx);}}}

2.获取文件散列值方法(两种):

a.根据上传文件,获取散列值

	/// <summary>/// 根据上传文件获取文件散列值/// </summary>/// <param name="file"></param>/// <returns></returns>public string CalculateSHA256Hash(IFormFile file){try{using (var sha256 = SHA256.Create()){using (var stream = file.OpenReadStream()){byte[] hashBytes = sha256.ComputeHash(stream);string hashString = BitConverter.ToString(hashBytes).Replace("-", String.Empty);return hashString;}}}catch (Exception ex){Console.WriteLine("Error calculating SHA256 hash: " + ex.Message);return null;}}

b.根据文件路径,获取散列值

    /// <summary>/// 根据文件路径获取文件散列值/// </summary>/// <param name="filePath"></param>/// <returns></returns>public string CalculateSHA256Hash(string filePath){try{using (FileStream stream = System.IO.File.OpenRead(filePath)){SHA256 sha = SHA256.Create();byte[] hash = sha.ComputeHash(stream);string hashString = BitConverter.ToString(hash).Replace("-", String.Empty);return hashString;}}catch (Exception ex){Console.WriteLine("Error calculating SHA256 hash: " + ex.Message);return null;}}

3.上传PDF文件,转化为Word文件方法:

    /// <summary>/// 文件上传/// </summary>/// <returns></returns>public ActionResult UploadFile(){var files = HttpContext.Request.Form.Files;if (files == null || files.Count <= 0){return Json(new { code = -1, msg = "请上传文件!" });}var file = files[0];if (file.ContentType != "application/pdf"){return Json(new { code = -1, msg = "不是PDF文件!" });}var SHA256Hash = CalculateSHA256Hash(file);long fileSize = file.Length;if (new FileConversionBll().ExistsSHA256Hash(SHA256Hash, fileSize)){var model = new FileConversionBll().GetFileBySHA256HashAndSize(SHA256Hash, fileSize);return Json(new { code = 0, msg = "",data = model.WordFilePath }); }else{string fileName = DateTime.Now.ToString("yyyyMMddHHmmssfff");//var filePath = $@"~/File/Pdf/{fileName}";string pdfFilePath = System.IO.Path.Combine("PDF文档路径", fileName + ".pdf");using (var fileStream = new FileStream(pdfFilePath, FileMode.Create)){file.CopyTo(fileStream);}string wordFilePath = System.IO.Path.Combine("Word文档路径", fileName + ".docx");//ConvertPdfToWord(pdfFilePath, wordFilePath);ConvertPdfToWordByText(pdfFilePath, wordFilePath);var res = new FileConversionBll().AddFileConversion(new FileConversion(){PdfFilePath = pdfFilePath,WordFilePath = wordFilePath,PdfSHA256Hash = SHA256Hash,FileSize = fileSize}) ;if (res){return Json(new { code = 0, msg = "",data = wordFilePath });}}return Json(new {code = -2,msg = "出错了!"});}

五.效果图:

旧版Spire.PDF包,只转化了10页:在这里插入图片描述
新版iTextSharp包,全部转化完成(但是去除了原本的Word文档格式):
在这里插入图片描述

http://www.ds6.com.cn/news/4382.html

相关文章:

  • 网站站内优化怎么做网页模板建站系统
  • 佛山专业的网站建设公司优帮云查询数据云查询
  • 上海微信网站建设兼容网站郑州seo优化公司
  • 公司门户网站怎么做免费的网页入口
  • 如何建立免费的网站重庆百度推广排名
  • 网站建设与功能模块网上营销新观察网
  • 网站建设网站制作公司百度搜索什么关键词排名
  • 怎么做物流网站市场推广计划怎么写
  • 1688是b2b吗做百度seo
  • 做外贸维护网站需要注意什么网络服务商主要包括
  • 苏州有什么好玩的地方济南网络优化网站
  • 制作静态网站的工具有哪些自己如何建立网站
  • 云盘可以做网站吗友情链接平台赚钱吗
  • 河南濮阳建设局网站官网seo优化找哪家做
  • 求一个网站网站推广服务外包
  • 网站建设如何跑单子最新注册域名查询
  • 南昌哪里可以做电商网站广州做seo整站优化公司
  • 百度推广客服电话24小时我赢seo
  • 教育公司 网站建设搜索引擎推广实训
  • 一级a做片性视频 网站在线观看武汉seo广告推广
  • 如何让自己的网站排在前面快速的网站设计制作
  • apache配置多个网站微信crm
  • 毕业设计网站开发传播易广告投放平台
  • 上海市官方网站常见的营销手段
  • 可以申请微信号的网站惠州搜索引擎优化
  • 最专业的礼品网站案例参考在线培训系统
  • 龙岗中心城网站建设网络营销渠道策略
  • 公司网站建设佛山哪家专业点击器免费版
  • logo做ppt模板下载网站淘宝指数查询入口
  • 网站初期如何推广360网站推广客服电话