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

C# PDF转HTML字符串

需要nuget安装Aspose.PDF插件,本文使用23.10.0版本

一、获取PDF文件,保存到某个路径;再读取返回字符串。

//html文件保存路径
string filePath = dirPath + "xxx.html";
if (!File.Exists(filePath))
{//获取pdf文件流Byte[] pdfByte = ……;var document = new Aspose.Pdf.Document(new MemoryStream(pdfByte));document.Save(filePath, SaveFormat.Html);
}//读取刚刚保存的文件  
string file = File.ReadAllText(filePath);
string oldPath = "xxx_files";
string newPath = ConfigurationManager.AppSettings["NurseHtmlIP"] + "/" + oldPath;
//剔除版权文字;替换本地css和图片路径 为 http路径,使得在第三方接口可调用
string targetHtml = file.Replace("Evaluation Only. Created with Aspose.PDF. Copyright 2002-2023 Aspose Pty Ltd.","").Replace(oldPath, newPath);
return targetHtml;

二、在用Base64加密,避免格式错误。

string base64Html = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(targetHtml)));

 三、前端显示,js方法。

//base64转字符串
function base64ToString(str) {return decodeURIComponent(atob(str).split('').map(function (c) {return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);}).join(''));
}var showInfo = function (htmlStr) {//把html显示到前端$("#ele_target").html(base64ToString(htmlStr));
}

http://www.lryc.cn/news/229084.html

相关文章:

  • el-table解决数据过少小于高度有留白的问题
  • vue实现无感刷新token
  • 竞赛选题 深度学习的动物识别
  • Python高级语法----Python C扩展与性能优化
  • 行业洞察:分布式云如何助力媒体与娱乐业实现创新与增长?
  • 【多线程 - 05、后台线程】
  • C语言之文件操作(剩余部分)
  • 【PC】开发者日志:竞技比赛验证系统强化
  • c++用map,创建类似于python中的字典
  • VuePress介绍及使用指南
  • Spring-Security前后端分离权限认证
  • Django中Cookie和Session的使用
  • 云原生周刊:KubeSphere 3.4.1 发布 | 2023.11.13
  • 逐帧动画demo
  • Mongodb 中,与索引相关的监控指标
  • 图论14-最短路径-Dijkstra算法+Bellman-Ford算法+Floyed算法
  • OpenCV 实现透视变换
  • ChinaSoft 论坛巡礼|开源软件供应链论坛
  • VUE 组合式API
  • 尝试使用php给pdf添加水印
  • ubuntu上安装edge浏览器
  • 动态切换 Spring Boot 打包配置:使用 Maven Profiles 管理 JAR 和 WAR
  • 微信小程序使用阿里巴巴矢量图标
  • 使用JAVA pdf转word
  • 成都瀚网科技有限公司抖音带货的正规
  • windows服务器热备、负载均衡配置
  • samba服务器搭建 挂载远程目录 常用配置参数介绍
  • Ansible命令使用
  • element 周选择器el-date-picker
  • No200.精选前端面试题,享受每天的挑战和学习