将html表转换为word文档或可编辑的pdf [英] convert html table to word document or editable pdf

查看:224
本文介绍了将html表转换为word文档或可编辑的pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用 jquery数据表 html表导出为pdf

I have been using jquery datatable and jsPDF, for exporting html table to pdf using codes like

pdf.fromHTML(
    source, // HTML string or DOM elem ref.
    margins.left, // x coord
    margins.top, { // y coord
        'width': margins.width, // max width of content on PDF
        'elementHandlers': specialElementHandlers
    }

是否有一个JavaScript库可将html表导出到 word文档(首选)或可编辑 pdf?"

Is there a javascript library to export the html table to word document(preferred) or editable pdf?

推荐答案

jspdf的作者使用纯客户端JavaScript称为

The author of jsPdf made a document generator for Microsoft Word documents in Pure client-side JavaScript called DOCX.js and recommends the usage of Stephen Hardy's DOCX.js.

DOCX.js依赖 JSZip 并支持粗体,斜体,下划线,删除线的编写,下标,上标,字体大小,字体颜色,突出显示和水平对齐方式.为了阅读,它支持上述所有功能以及嵌入式PNG.将来可能会支持表格和列表(项目符号和编号),但目前尚不支持.

DOCX.js depends on JSZip and supports the writing of bold, italic, underline, strikethrough, subscript, superscript, font sizes, font color, highlights, and horizontal alignment. For reading, it supports all of the above plus embedded PNGs. Support for tables and lists (bulleted and numbered) will likely come in the future, but is not currently present.

ZerdaH的叉子的演示用法:

var docDOM = document.getElementById('example');

var docObject = docx.export(docDOM, // required DOM Object
{
    creator: "Creator", // optional String
    lastModifiedBy: "Last person to modify", // optional String
    created: new Date(), // optional Date Object
    modified: new Date() // optional Date Object
});

var link = document.createElement('a');
link.appendChild(document.createTextNode("Download Link Text"));
link.title = "Download Title";
link.download = "FilenameHere.docx";
link.href = docObject.href();
document.getElementById("example").appendChild(link);

这篇关于将html表转换为word文档或可编辑的pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆