news 2026/1/22 5:33:04

TinyMCE导入MathType公式保留矢量格式

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
TinyMCE导入MathType公式保留矢量格式

江苏.NET程序员的CMS文档神器(680元保姆级方案)

“各位老铁,最近接了个企业官网外包项目,客户爸爸非要让我给TinyMCE编辑器加上Word/Excel/PPT/PDF导入功能,还要支持微信公众号内容粘贴。预算只有680元,但需求比我的头发还密集——不过别慌,本程序员最擅长在刀尖上跳舞(毕竟头发掉光了也不怕)!”


一、方案亮点(打工人友好版)

  • 开箱即用:解压即插,TinyMCE工具栏秒变「文档神器」按钮(亲测Vue3兼容)
  • 全格式通吃:Word/Excel/PPT/PDF/公众号内容全覆盖(WPS粘Word也不崩)
  • 公式高清:Latex自动转MathML,手机/平板/小程序都能高清显示(实测iPhone 14 Pro Max没问题)
  • 预算友好:680元买断源码(含部署教程),终身免费升级(比奶茶还划算!)
  • 集成简单:复制粘贴就能用,不影响现有系统(客户说「这钱花得值」)

二、前端实现(TinyMCE插件集成)

1. 插件目录结构(直接丢进TinyMCE的plugins文件夹)

/tiny-mce/plugins/doc_magic/ ├─ dialog.html # 多功能操作面板(Vue3适配版) ├─ doc_magic.js # 核心插件逻辑(超简单,就200行) └─ style.css # 样式文件(兼容IE8+)

2. 核心代码(doc_magic.js)—— 学长亲自写的,注释超详细

// 注册TinyMCE插件(Vue3/React通用,复制就能用)tinymce.PluginManager.add('doc_magic',function(editor,url){// 创建万能按钮(用了阿里云同款绿,好看!)constbtn=editor.ui.registry.addButton('doc_magic',{icon:'document',tooltip:'文档神器(粘贴/导入)',onAction:()=>showMagicDialog(editor)// 点击触发弹窗});// 显示多功能弹窗(Vue3轻量适配,不影响现有系统)functionshowMagicDialog(editor){editor.windowManager.open({title:'文档导入神器(打工人亲测)',width:900,height:650,body:{type:'tabpanel',tabs:[{title:'粘贴内容',items:[{type:'textarea',name:'pasteContent',label:'粘贴Word/公众号内容(Ctrl+V)',multiline:true,maxHeight:300},{type:'button',text:'提取内容(打工人推荐)',onclick:()=>processPaste(editor)// 处理粘贴},{type:'htmlpanel',htmlId:'pastePreview'// 预览区域}]},{title:'导入文档',items:[{type:'filepicker',name:'fileUpload',label:'选文件(支持docx/xlsx/pptx/pdf)',onchange:(e)=>handleFileUpload(e,editor)// 处理上传},{type:'htmlpanel',htmlId:'filePreview'// 预览区域}]},{title:'公众号导入',items:[{type:'textbox',name:'wechatUrl',label:'公众号文章链接(例:https://mp.weixin.qq.com/...)',maxWidth:500},{type:'button',text:'抓取内容(打工人实测可用)',onclick:()=>fetchWechatContent(editor)// 抓取公众号},{type:'htmlpanel',htmlId:'wechatPreview'// 预览区域}]}]},buttons:[{type:'cancel',text:'关闭(打工人说别点这个)'}]});}// 处理粘贴内容(图片自动上传OSS,保留样式)asyncfunctionprocessPaste(editor){constcontent=tinymce.activeEditor.dom.get('pasteContent').value;// 调用后端API(ASP.NET WebForm写的,超简单)constres=awaitfetch('/api/doc/process-paste',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({content})});constdata=awaitres.json();tinymce.activeEditor.dom.get('pastePreview').innerHTML=data.content;// 显示预览}// 处理文件上传(自动上传图片到OSS)asyncfunctionhandleFileUpload(e,editor){constfile=e.target.files[0];constformData=newFormData();formData.append('file',file);// 调用后端上传接口(ASP.NET处理OSS上传)constres=awaitfetch('/api/doc/upload-file',{method:'POST',body:formData});constdata=awaitres.json();tinymce.activeEditor.dom.get('filePreview').innerHTML=data.content;// 显示预览}// 抓取公众号内容(自动下载图片)asyncfunctionfetchWechatContent(editor){consturl=tinymce.activeEditor.dom.get('wechatUrl').value;constres=awaitfetch('/api/doc/fetch-wechat',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({url})});constdata=awaitres.json();tinymce.activeEditor.dom.get('wechatPreview').innerHTML=data.content;// 显示预览}});

3. 操作面板(dialog.html)—— 打工人设计的,颜值在线

文档神器(打工人版) // 兼容老浏览器的DOM操作(打工人加的,防止IE8崩) function getElementsByClassName(className) { return document.querySelectorAll('.' + className); }

三、后端实现(ASP.NET WebForm)—— 打工人用VS2022搭的,超省心

1. 环境准备(宿舍电脑/实验室服务器都能跑)

  • Windows 10/Server 2019(推荐Win10,开发调试方便)
  • Visual Studio 2022(社区版免费,打工人用的是这个)
  • .NET Framework 4.8(WebForm最佳拍档)
  • SQL Server 2019(打工人用的是阿里云RDS,免费版够用)
  • 阿里云OSS SDK(Install-Package Aliyun.OSS.SDK.NetCore -Version 3.15.1

2. OSS配置(Web.config)—— 打工人写死的,直接填你的OSS信息

3. 核心处理类(App_Code/DocProcessor.cs)—— 打工人写的,注释超详细

usingSystem;usingSystem.IO;usingSystem.Text.RegularExpressions;usingAliyun.OSS;usingMicrosoft.Office.Interop.Word;// 需安装Office(打工人用WPS替代)usingAspose.Words;// 免费库,需自行下载(打工人用的是免费版)publicclassDocProcessor{// OSS配置(从Web.config读)privatestaticstringossEndpoint=ConfigurationManager.AppSettings["OSS_Endpoint"];privatestaticstringossAccessKey=ConfigurationManager.AppSettings["OSS_AccessKey"];privatestaticstringossSecret=ConfigurationManager.AppSettings["OSS_Secret"];privatestaticstringossBucket=ConfigurationManager.AppSettings["OSS_Bucket"];// 处理粘贴的Word内容(图片上传OSS,保留样式)publicstringProcessPastedWord(stringhtml){// 1. 清理Word垃圾标签(打工人实测有效)stringcleanHtml=CleanWordTags(html);// 2. 提取并上传图片(二进制存储,非Base64)cleanHtml=UploadImages(cleanHtml);// 3. 转换Latex为MathML(调用MathJax免费API)cleanHtml=ConvertLatexToMathML(cleanHtml);returncleanHtml;}// 解析Word文档(.docx)publicstringParseWord(stringfilePath){// 打工人用Aspose.Words(免费版)解析,比Office Interop更稳定Documentdoc=newDocument(filePath);StringBuilderhtml=newStringBuilder("");// 处理段落(保留字体/字号/颜色)foreach(Paragraphparaindoc.Paragraphs){html.Append("");foreach(Runruninpara.Runs){html.Append("");html.Append(run.Text);html.Append("");}html.Append("");}// 处理表格(保留形状组)foreach(Tabletableindoc.Tables){html.Append("");foreach(Rowrowintable.Rows){html.Append("");foreach(Cellcellinrow.Cells){html.Append("");}html.Append("");}html.Append("").Append(ParseCell(cell)).Append("");}html.Append("");returnhtml.ToString();}// 辅助方法:清理Word垃圾标签(打工人调了3晚的bug!)privatestringCleanWordTags(stringhtml){returnRegex.Replace(html,@".*?","",RegexOptions.Singleline).Replace("class=""MsoNormal""","").Replace("]+src=""data:image/(png|jpg);base64,(.*?)""[^>]*>");foreach(Matchmatchinmatches){stringbase64=match.Groups[2].Value;byte[]bytes=Convert.FromBase64String(base64);stringtempPath=Path.GetTempFileName()+".png";File.WriteAllBytes(tempPath,bytes);// 上传到OSS(打工人写的方法,超简单)stringossUrl=UploadToOSS(tempPath,"paste_img_"+DateTime.Now.Ticks+".png");html=html.Replace(match.Value,$"");File.Delete(tempPath);// 删除临时文件}returnhtml;}// 辅助方法:上传文件到OSS(打工人封装的,超好用)privatestringUploadToOSS(stringfilePath,stringfileName){OssClientossClient=newOssClient(ossEndpoint,ossAccessKey,ossSecret);stringobjectKey=$"cms_docs/{fileName}";// 存储路径:cms_docs/文件名try{ossClient.PutObject(ossBucket,objectKey,newFileStream(filePath,FileMode.Open));return$"https://{ossBucket}.{ossEndpoint}/{objectKey}";}catch(Exceptionex){return$"上传失败:{ex.Message}";}}// 辅助方法:Latex转MathML(调用MathJax免费API)privatestringConvertLatexToMathML(stringhtml){returnRegex.Replace(html,@"\$(.*?)\$",match=>{stringlatex=match.Groups[1].Value;try{// 调用MathJax API(免费,实测可用)stringmathml=newWebClient().DownloadString($"https://mathjax.github.io/MathJax-demos-web/convert-latex-to-mathml/?latex={latex}");returnmathml.Contains("false;}

四、部署指南(打工人手把手教,5分钟搞定)

1. 环境搭建(宿舍电脑/实验室服务器)

  1. 安装Windows 10/Server 2019(推荐Win10,开发调试方便)
  2. 安装Visual Studio 2022(社区版免费,https://visualstudio.microsoft.com/zh-hans/vs/)
  3. 安装.NET Framework 4.8(https://dotnet.microsoft.com/download/dotnet-framework/net48)
  4. 安装SQL Server 2019(https://dev.mysql.com/downloads/mysql/,打工人用的是阿里云RDS)
  5. 注册阿里云OSS(https://oss.console.aliyun.com/),创建Bucket并获取AccessKey

2. 集成步骤(复制粘贴就能用)

  1. doc_magic插件文件夹丢进TinyMCE的plugins目录(路径:tinymce/plugins/
  2. 在TinyMCE初始化配置(tinymce.init.js)中添加按钮:
    tinymce.init({selector:'#editor',// 你的编辑器容器IDplugins:'doc_magic',// 添加插件toolbar:'doc_magic bold italic'// 工具栏显示按钮});
  3. Web.config中的OSS信息改成你自己的(阿里云控制台获取)
  4. 把项目发布到IIS(发布IIS、FTP等选择服务器

五、群组福利(打工人建的,专搞外包)

加群223813913,解锁以下隐藏福利:

  • 新人红包:1~99元随机现金(手慢无!打工人自己发的)
  • 接单特权:优先获取企业CMS外包项目(单价1k~5k,打工人带飞)
  • 提成暴击:推荐客户拿20%提成(1万订单直接拿2k!打工人算过,一个月接5单够生活费)
  • 内推通道:打工人在上海软件园有资源,国企/事业单位技术岗直推(月薪8k+)

群友真实反馈:“上周推荐了个政府项目,提成拿了3k,够买台新笔记本了!”


四、薅羊毛与避坑指南

  1. 免费资源

    • 阿里云OSS临时授权(领用地址:aliyun.com/activity/oss-free)
    • Visual Studio 2022社区版(白嫖永久授权)
    • 群福利:输入暗号"企业官网救我"领:
      ✅ 完整插件包
      ✅ OSS上传Demo
      ✅ 公式转换工具
      ✅ 客户催稿应对话术
  2. 预算控制

    • 插件费用:$49(约350元)
    • 阿里云OSS流量:预计$5(约35元)
    • 剩余预算:$17(买咖啡续命)

五、求职与外包彩蛋

"顺便问下,有南京/苏州的.NET岗位吗?本人技能树:
✔️ 精通Ctrl+C/V
✔️ 熟练百度Stack Overflow
✔️ 擅长在GitHub找付费插件
✔️ 阿里云ECS部署经验+1

(附简历链接:github.com/your-name/resume)"


最终效果
客户测试时惊呼:“这Word粘贴比我老婆的复制粘贴还智能!”
我淡定回复:“基本操作,坐下~”(实际在群里疯狂@大佬求救)

(群公告:新人红包已就位!推荐客户提20%,黄金会员提50%!错过这村……我就去你家门口贴小广告!)

源代码包

  • 前端插件:github.com/your-repo/tinymce-document-import
  • 后端Demo:github.com/your-repo/cms-backend
  • 部署文档:github.com/your-repo/cms-docs

(群号:223813913,暗号"企业官网救我"领红包!PS:本群主已靠推荐提成喜提奶茶自由~)

复制插件

安装jquery

npm install jquery

在组件中引入

// 引入tinymce-vueimportEditorfrom'@tinymce/tinymce-vue'import{WordPaster}from'../../static/WordPaster/js/w'import{zyOffice}from'../../static/zyOffice/js/o'import{zyCapture}from'../../static/zyCapture/z'

添加工具栏

//添加导入excel工具栏按钮(function(){'use strict';varglobal=tinymce.util.Tools.resolve('tinymce.PluginManager');functionselectLocalImages(editor){WordPaster.getInstance().SetEditor(editor).importExcel()}varregister$1=function(editor){editor.ui.registry.addButton('excelimport',{text:'',tooltip:'导入Excel文档',onAction:function(){selectLocalImages(editor)}});editor.ui.registry.addMenuItem('excelimport',{text:'',tooltip:'导入Excel文档',onAction:function(){selectLocalImages(editor)}});};varButtons={register:register$1};functionPlugin(){global.add('excelimport',function(editor){Buttons.register(editor);});}Plugin();}());//添加word转图片工具栏按钮(function(){'use strict';varglobal=tinymce.util.Tools.resolve('tinymce.PluginManager');functionselectLocalImages(editor){WordPaster.getInstance().SetEditor(editor);WordPaster.getInstance().importWordToImg()}varregister$1=function(editor){editor.ui.registry.addButton('importwordtoimg',{text:'',tooltip:'Word转图片',onAction:function(){selectLocalImages(editor)}});editor.ui.registry.addMenuItem('importwordtoimg',{text:'',tooltip:'Word转图片',onAction:function(){selectLocalImages(editor)}});};varButtons={register:register$1};functionPlugin(){global.add('importwordtoimg',function(editor){Buttons.register(editor);});}Plugin();}());//添加粘贴网络图片工具栏按钮(function(){'use strict';varglobal=tinymce.util.Tools.resolve('tinymce.PluginManager');functionselectLocalImages(editor){WordPaster.getInstance().SetEditor(editor);WordPaster.getInstance().UploadNetImg()}varregister$1=function(editor){editor.ui.registry.addButton('netpaster',{text:'',tooltip:'网络图片一键上传',onAction:function(){selectLocalImages(editor)}});editor.ui.registry.addMenuItem('netpaster',{text:'',tooltip:'网络图片一键上传',onAction:function(){selectLocalImages(editor)}});};varButtons={register:register$1};functionPlugin(){global.add('netpaster',function(editor){Buttons.register(editor);});}Plugin();}());//添加导入PDF按钮(function(){'use strict';varglobal=tinymce.util.Tools.resolve('tinymce.PluginManager');functionselectLocalImages(editor){WordPaster.getInstance().SetEditor(editor);WordPaster.getInstance().ImportPDF()}varregister$1=function(editor){editor.ui.registry.addButton('pdfimport',{text:'',tooltip:'导入pdf文档',onAction:function(){selectLocalImages(editor)}});editor.ui.registry.addMenuItem('pdfimport',{text:'',tooltip:'导入pdf文档',onAction:function(){selectLocalImages(editor)}});};varButtons={register:register$1};functionPlugin(){global.add('pdfimport',function(editor){Buttons.register(editor);});}Plugin();}());//添加导入PPT按钮(function(){'use strict';varglobal=tinymce.util.Tools.resolve('tinymce.PluginManager');functionselectLocalImages(editor){WordPaster.getInstance().SetEditor(editor);WordPaster.getInstance().importPPT()}varregister$1=function(editor){editor.ui.registry.addButton('pptimport',{text:'',tooltip:'导入PowerPoint文档',onAction:function(){selectLocalImages(editor)}});editor.ui.registry.addMenuItem('pptimport',{text:'',tooltip:'导入PowerPoint文档',onAction:function(){selectLocalImages(editor)}});};varButtons={register:register$1};functionPlugin(){global.add('pptimport',function(editor){Buttons.register(editor);});}Plugin();}());//添加导入WORD按钮(function(){'use strict';varglobal=tinymce.util.Tools.resolve('tinymce.PluginManager');functionselectLocalImages(editor){WordPaster.getInstance().SetEditor(editor).importWord()}varregister$1=function(editor){editor.ui.registry.addButton('wordimport',{text:'',tooltip:'导入Word文档',onAction:function(){selectLocalImages(editor)}});editor.ui.registry.addMenuItem('wordimport',{text:'',tooltip:'导入Word文档',onAction:function(){selectLocalImages(editor)}});};varButtons={register:register$1};functionPlugin(){global.add('wordimport',function(editor){Buttons.register(editor);});}Plugin();}());//添加WORD粘贴按钮(function(){'use strict';varglobal=tinymce.util.Tools.resolve('tinymce.PluginManager');varico="http://localhost:8080/static/WordPaster/plugin/word.png"functionselectLocalImages(editor){WordPaster.getInstance().SetEditor(editor).PasteManual()}varregister$1=function(editor){editor.ui.registry.addButton('wordpaster',{text:'',tooltip:'Word一键粘贴',onAction:function(){selectLocalImages(editor)}});editor.ui.registry.addMenuItem('wordpaster',{text:'',tooltip:'Word一键粘贴',onAction:function(){selectLocalImages(editor)}});};varButtons={register:register$1};functionPlugin(){global.add('wordpaster',function(editor){Buttons.register(editor);});}Plugin();}());

在线代码:

添加插件

// 插件plugins:{type:[String,Array],// default: 'advlist anchor autolink autosave code codesample colorpicker colorpicker contextmenu directionality emoticons fullscreen hr image imagetools importcss insertdatetime link lists media nonbreaking noneditable pagebreak paste preview print save searchreplace spellchecker tabfocus table template textcolor textpattern visualblocks visualchars'default:'autoresize code autolink autosave image imagetools paste preview table powertables'},

点击查看在线代码

初始化组件

// 初始化WordPaster.getInstance({// 上传接口:http://www.ncmem.com/doc/view.aspx?id=d88b60a2b0204af1ba62fa66288203edPostUrl:'http://localhost:8891/upload.aspx',// 为图片地址增加域名:http://www.ncmem.com/doc/view.aspx?id=704cd302ebd346b486adf39cf4553936ImageUrl:'http://localhost:8891{url}',// 设置文件字段名称:http://www.ncmem.com/doc/view.aspx?id=c3ad06c2ae31454cb418ceb2b8da7c45FileFieldName:'file',// 提取图片地址:http://www.ncmem.com/doc/view.aspx?id=07e3f323d22d4571ad213441ab8530d1ImageMatch:''})

在页面中引入组件

功能演示

编辑器

在编辑器中增加功能按钮

导入Word文档,支持doc,docx

导入Excel文档,支持xls,xlsx

粘贴Word

一键粘贴Word内容,自动上传Word中的图片,保留文字样式。

Word转图片

一键导入Word文件,并将Word文件转换成图片上传到服务器中。

导入PDF

一键导入PDF文件,并将PDF转换成图片上传到服务器中。

导入PPT

一键导入PPT文件,并将PPT转换成图片上传到服务器中。

上传网络图片

一键自动上传网络图片。

下载示例

点击下载完整示例

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/1/17 12:51:41

基于java的SpringBoot/SSM+Vue+uniapp的少儿编程在线学习系统的详细设计和实现(源码+lw+部署文档+讲解等)

文章目录前言详细视频演示具体实现截图技术栈后端框架SpringBoot前端框架Vue持久层框架MyBaitsPlus系统测试系统测试目的系统功能测试系统测试结论为什么选择我代码参考数据库参考源码获取前言 🌞博主介绍:✌全网粉丝15W,CSDN特邀作者、211毕业、高级全…

作者头像 李华
网站建设 2026/1/20 9:40:32

安卓手机抓取崩溃日志的三种方式

安卓手机抓取崩溃日志的三种方式: 1.通过adb logcat 来获取: 使用场景:测试或者开发小伙伴 抓取。 先执行adb logcat -c 清理缓存日志 接着,抓取当前时间段开始的日志: adb logcat -v time >D:/crash.log 也可以抓取指定进程的…

作者头像 李华
网站建设 2026/1/21 5:03:38

稳定性增强、界面焕新:qData 数据中台开源版发布最新优化版本

在近期的更新中,我们将商业版用户反馈的关键修复与优化内容统一同步至开源版。此次更新覆盖系统稳定性、数据研发体验、资产管理、UI 表现等多个方面,大幅提升了整体使用体验。无论你来自社区还是企业侧,本次更新都将带来更顺畅、更可靠的数据…

作者头像 李华
网站建设 2026/1/20 19:41:46

16、深入了解psad:从高级功能到主动响应

深入了解psad:从高级功能到主动响应 1. 基于p0f签名的操作系统指纹识别 psad可以通过将SYN数据包中的TCP选项与p0f签名进行匹配,识别出正在探测iptables防火墙的特定远程操作系统。不过,这一功能需要使用 --log-tcp-options 参数才能实现。因此,在将默认的LOG规则添加到…

作者头像 李华
网站建设 2026/1/12 6:45:44

26、端口敲门与单包授权:网络安全认证技术对比

端口敲门与单包授权:网络安全认证技术对比 1. 端口敲门技术基础 端口敲门(Port Knocking)是一种增强网络服务安全性的技术,它通过特定的端口访问序列来临时重新配置数据包过滤器,从而允许特定IP地址访问受保护的服务。 1.1 自定义UDP校验和示例 通过执行以下脚本并使用…

作者头像 李华
网站建设 2025/12/26 5:22:39

NumPy 实用文档

NumPy 实用文档 文章目录NumPy 实用文档一、Numpy基础操作1. 数组创建(Array Creation)2. 随机数生成(Random)3. 数组形状操作(Shape Manipulation)4. 数组连接(Concatenate & Stack&#x…

作者头像 李华