mammoth+html2canvas实现浏览器中打开word文档预览下载为图片代码
代码语言:html
所属分类:其他
代码描述:mammoth+html2canvas实现浏览器中打开word文档预览下载为图片代码,mammoth解析word文档docx为html,html2canvas负责将html变成图片下载。
代码标签: mammoth html2canvas 浏览器 打开 word 文档 预览 下载 图片 代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <style> .custom-file-upload{ margin: 100px; } .inputfile { width: 0.1px; height: 0.1px; opacity: 0; overflow: hidden; position: absolute; z-index: -1; } .custom-file-upload label { display: inline-block; padding: 10px 20px; font-size: 1rem; letter-spacing: 1px; text-align: center; cursor: pointer; background-color: #f8f8f8; border: 2px solid #d3d3d3; border-radius: 4px; } .custom-file-upload label:hover { background-color: #e8e8e8; } </style> </head> <body> <div class="custom-file-upload "> <input id="document" class="inputfile" type="file" accept=".doc,.docx" /> <label for="document">点击这里打开word文件预览导出图片</label> <div style="width: 100%;"> <div id="output" ></div> </div> </div> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/mammoth.browser.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/html2canvas.js"></script> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/filesaver.js"></script> <script type="text/javascript"> document.getElementById("document") .addEventListener("change", readFileInputEventAsArrayBuffer, false); function displayResult(result) { let html = result.value; let newHTML = html.replace(//g, '') .replace('<h1>', '<h1 style="text-align: center;">') .replace(/<table>/g, '<table style="border-collapse: collapse;">') .replace(/<tr>/g, '<tr style="height: 30px;">') .replace(/<td>/g, '<td style="border: 1px solid pink;">') .........完整代码请登录后点击上方下载按钮下载查看
网友评论0