1 Star 12 Fork 2

弄个锤子/html2pdf

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
3年前
Loading...
README
MIT

html2pdf

介绍

将html生成pdf,依赖html2canvas和jspdf

安装

npm install @sangtian152/html2pdf --save
# or 
yarn add @sangtian152/html2pdf

使用

import html2pdf from '@sangtian152/html2pdf';

html2pdf(element, options);

参数

参数 说明 类型 可选值 默认值
element 要生成pdf的dom元素 Element
options 配置参数,详见options Object

options

参数 说明 类型 可选值 默认值
title 生成的pdf文件名 String pdf
scale html2canvas的放大倍数,值越大生成的pdf越清晰,但相应的会影响性能 Number
padding pdf页边距 Array
format pdf纸型 String A4
orientation 方向(纵向、横向) String P,L P
unit 单位 String pt
stretch 当打印内容宽度小于pdf宽度时,是否拉伸 Boolean true
background pdf背景色 String #ffffff
useCORS 是否尝试使用CORS从服务器加载图像(需后端开启跨域) Boolean false
minimumUnit 最小分割单元,分页时最小分割单元不会被分成半截(如果单个最小分割单元高度已经超出PDF页面高度也会被分割) String css选择器
ignoreElements 设置排除元素,参数为当前dom元素,要求返回 Boolean Function

最新版本

NPM version

MIT License Copyright (c) 2021 sangtian152 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

将html生成pdf,依赖html2canvas和jspdf 展开 收起
JavaScript 等 2 种语言
MIT
取消

发行版

暂无发行版

贡献者 (1)

全部

近期动态

1年多前创建了任务 #I8OZZ0 背景图片转换不了。
2年多前更改了任务 #I60JN2 图片超过1000张,会全是黑的图片 的状态为已完成
2年多前评论了任务 #I60JN2 图片超过1000张,会全是黑的图片
2年多前创建了任务 #I60JN2 图片超过1000张,会全是黑的图片
2年多前更改了任务 #I4S996 生成的html导出到pdf全是黑的图片 的状态为已完成
加载更多
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/sangtian152/html2pdf.git
git@gitee.com:sangtian152/html2pdf.git
sangtian152
html2pdf
html2pdf
master

搜索帮助