本文介绍了使用JavaScript生成PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将XML数据转换为网页中的PDF文件,我希望我可以在JavaScript中完全执行此操作。我需要能够绘制文本,图像和简单的形状。我希望能够在浏览器中完全做到这一点。

I’m trying to convert XML data into PDF files from a web page and I was hoping I could do this entirely within JavaScript. I need to be able to draw text, images and simple shapes. I would love to be able to do this entirely in the browser.

推荐答案

我刚刚编写了一个名为,仅使用Javascript生成PDF。它还很年轻,我很快就会添加功能和错误修复。还有一些关于不支持数据URI的浏览器的变通方法的想法。它是在自由MIT许可下获得许可的。

I've just written a library called jsPDF which generates PDFs using Javascript alone. It's still very young, and I'll be adding features and bug fixes soon. Also got a few ideas for workarounds in browsers that do not support Data URIs. It's licensed under a liberal MIT license.

在我开始写这个问题之前,我遇到过这个问题并且认为我会回来让你知道:)

I came across this question before I started writing it and thought I'd come back and let you know :)

示例创建一个Hello WorldPDF文件。

Example create a "Hello World" PDF file.

// Default export is a4 paper, portrait, using milimeters for units
var doc = new jsPDF()

doc.text('Hello world!', 10, 10)
doc.save('a4.pdf')
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.5/jspdf.debug.js"></script>

这篇关于使用JavaScript生成PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 04:16