下载图表和表格的PDF格式
Download graph as well as table as a PDF
我有一个D3图表和一个引导表。我想下载图形和表,因为它看起来在HTMl页面上。我找到了一些答案,但他们要么下载表格,要么下载图表。我想要一个相同的组合PDF。我试过用jspdf,但我卡住了。
下面是jsfiddle的链接。
http://jsfiddle.net/xzZ7n/3301/function demoFromHTML() {
var pdf = new jsPDF('p', 'pt', 'letter');
// source can be HTML-formatted string, or a reference
// to an actual DOM element from which the text will be scraped.
source = $('#customers')[0];
// we support special element handlers. Register them with jQuery-style
// ID selector for either ID or node name. ("#iAmID", "div", "span" etc.)
// There is no support for any other type of selectors
// (class, of compound) at this time.
specialElementHandlers = {
// element with id of "bypass" - jQuery style selector
'#bypassme': function (element, renderer) {
// true = "handled elsewhere, bypass text extraction"
return true
}
};
margins = {
top: 80,
bottom: 60,
left: 40,
width: 522
};
// all coords and widths are in jsPDF instance's declared units
// 'inches' in this case
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
},
function (dispose) {
// dispose: object with X, Y of the last line add to the PDF
// this allow the insertion of new lines after html
pdf.save('Test.pdf');
}, margins);
}
后端是spring MVC。JQuery或JAVA的下载功能都可以。
因此,出于好奇和考虑,我不完全确定jsPDF是否最可靠。首先,使用d3.js将图形呈现为SVG,因此最好的选择是将SVG转换为PDF。我发现了这个问题,似乎fromHTML
仍然是一个非常新的方法(它甚至没有在内部文档中…)。
他们确实提到他们支持addSVG
方法,但我发现这也可能不像你想的那样理想。听起来它仍然有一些问题,你并不是唯一一个问这个库的SVG。
看了看之后,我认为这个答案总结得最好——签出PDFKit,它给了你一种将SVG渲染成PDF的方法,尽管在看了文档之后,似乎它们只允许你画画?它没有展示向PDF文档添加SVG的方法。答案还提到了一个svgToPDF插件的jsPDF,但我看了看,显然这是合并了一段时间前,所以我不确定如果它实际上是一个插件或已经内置。
希望这能提供更多的见解。我自己也对这个问题很好奇。如果我找到更好的信息,我会更新这个答案。
相关文章:
- 如何使用javascript或html下载PDF格式的填写表单
- 如何使用chart.js导出Excel和PDF格式的图表
- 使用window.print内容以pdf格式下载网页
- 提交了一个PDF格式的PHP脚本只适用于Adobe阅读器XI
- 如何发布到URL并打开一个新窗口以显示pdf格式的响应
- 如何在不强制的情况下添加条件文本?[101,pdf格式]
- 谷歌应用程序将电子邮件表单脚本转换为PDF格式,但希望清除一些单元格
- 下载pdf格式不正确
- 将ng-grid数据导出为angularjs中的CSV和PDF格式
- 让 Javascript 在以 ABC pdf 格式渲染 pdf 之前完成
- 只允许提交pdf格式/图片,而不是空白
- 将flot图表保存为图像或pdf格式
- 以PDF格式下载带有图像和图案的SVG
- 程序验证+以Acrobat PDF格式提交
- 是否可以将javascript添加到pdf格式的图像中
- 使用python或js以pdf格式下载带有动态css的html
- 下载图表和表格的PDF格式
- pdf格式的加载栏
- 以pdf格式下载D3图
- 当打印按钮被点击,它打印整个页面的pdf格式,包括导航栏和一切.如何打印只是报价