如何从html网页生成PDF? [英] How to generate a pdf from html web page?

查看:136
本文介绍了如何从html网页生成PDF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个图书馆,以便在按钮点击事件后将我的网页转换为PDF文件。
我想要 jspdf ,但它没有CSS打印,我怎样才能使用 JavaScript / jQuery 并保持我的CSS?或者我可以选择其他的CSS?

I'm looking for a library to transform my web page into a PDF file after click event from a button. I'm trying jspdf, but it prints without the CSS, how can I make this using JavaScript/jQuery and keep my CSS? Or another CSS that I can choose?

推荐答案

这是你的库(GitHub):

Here's your library (GitHub):
https://github.com/Xportability/css-to-pdf

这是你的小提琴:

http:// jsfiddle.net/kstubs/jrtM5/

下面是一个工作演示:

http://xep.cloudformatter.com/doc/

Here's a working demo:
http://xep.cloudformatter.com/doc/

目前没有使用说明,但下面的示例(查看源代码)应该是不言自明的(查找Print It按钮),这里或多或少是Format方法可以理解的其他选项/参数。

Currently there are not useage instructions, but following along with the samples (view source) should be pretty self-explanatory (look for the Print It buttons) and here is, more or less the additional options/parameters that the Format method understands.

options 
{
    pageWidth: "8.5in",             
    pageHeight: "11in", 
    pageMargin: ".25in", 
    pageMarginTop: "1in",
    pageMarginRight: "1in",
    pageMarginBottom: "1in",
    pageMarginLeft: "1in",
    render: ("none"|"newwin<default>"|embed"|"download<default IE>"),
    foStyle: { 
        // puts fo style attributes on the root, ex. fontSize:14px
        foStyleName: 'value', ...
    }           
}

以下是当前支持的CSS属性列表。

Here is list of CSS attributes that are currently supported.

[
    'lineHeight', 
    'alignmentBaseline', 
    'backgroundImage', 'backgroundPosition', 'backgroundRepeat', 'backgroundColor',
    'baselineShift', 
    'border',
    'borderWidth', 'borderColor','borderStyle',
    'borderTop','borderLeft','borderRight','borderBotttom',
    'borderTopWidth','borderTopStyle','borderTopColor', 
    'borderBottomWidth','borderBottomStyle','borderBottomColor',
    'borderLeftWidth','borderLeftStyle','borderLeftColor',
    'borderRightWidth','borderRightStyle','borderRightColor',
    'borderCollapse',             
    'clear', 'color', 
    'display', 'direction', 'dominantBaseline', 
    'fill', 'float', 
    'fontStyle', 'fontVariant', 'fontWeight', 'fontSize', 'fontFamily', 
    'listStyleType', 'listStyleImage', 'letterSpacing', 
    'marginTop', 'marginBottom', 'marginLeft', 'marginRight','orphans', 
    'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft',
    'pageBreakAfter', 'pageBreakBefore', 
    'tableLayout', 
    'textAlign', 'textAnchor','textDecoration', 'textIndent', 'textTransform', 
    'verticalAlign',
    'widows', 'wordSpacing', 'width'
]

希望这有助于!

这篇关于如何从html网页生成PDF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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