javascript: convert html web pages to pdf in javascript

 

https://github.com/parallax/jsPDF
http://mrrio.github.io/jsPDF/examples/basic.html
https://rawgit.com/MrRio/jsPDF/master/docs/jsPDF.html

https://github.com/spipu/html2pdf

https://parall.ax/products/jspdf
https://github.com/eKoopmans/html2pdf.js
https://github.com/niklasvh/html2canvas
https://github.com/stefanpenner/es6-promise

https://github.com/jakerella/jquery-mockjax

https://github.com/caprica/jquery-orgchart

https://github.com/yWorks/svg2pdf.js
https://github.com/caprica/jquery-orgchart
http://rlopez0689.github.io/OrgChartJit/

yFiles
https://github.com/yWorks/yfiles-for-html-demos
https://live.yworks.com/demos/complete/interactiveorgchart/

 

 

html:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>html convert Document 捷为工作室</title>
    <meta name="Description" content="捷为工作室"/>
    <meta name="Keywords" content="捷为工作室"/>
    <meta name="author" content="geovindu Geovin Du"
    <link rel="stylesheet" href="bootstrap/4.5.0/css/bootstrap.min.css" crossorigin="anonymous">
    <link rel="stylesheet" href="pdf.css"  media="all" />
    <script type="text/javascript">
                document.write("<script type='text/javascript' src='pdf.js?v=" + Math.random() + "'></s" + "cript>");
 
        </script>
    <script>
    //https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.9.2/html2pdf.bundle.js
    //https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css
    </script>
    <script src="html2pdf.js/0.9.2/html2pdf.bundle.js"></script>
 
</head>
 
<body>
    <div class="container d-flex justify-content-center mt-50 mb-50">
        <div class="row">
            <div class="col-md-12 text-right mb-3">
                <button class="btn btn-primary" id="download"> 下载 pdf</button>
            </div>
            <div class="col-md-12">
                <div class="card" id="invoice">
                    <div class="card-header bg-transparent header-elements-inline">
                        <h6 class="card-title text-primary">捷为工作室:售销发票</h6>
                    </div>
                    <div class="card-body">
                        <div class="row">
                            <div class="col-sm-6">
                                <div class="mb-4 pull-left">
 
                                    <ul class="list list-unstyled mb-0 text-left">
                                        <li>2269 Six Sigma</li>
                                        <li>深圳市</li>
                                        <li>+86 0755 8239 7507 </li>
                                    </ul>
                                </div>
                            </div>
                            <div class="col-sm-6">
                                <div class="mb-4 ">
                                    <div class="text-sm-right">
                                        <h4 class="invoice-color mb-2 mt-md-2">NO #BBB1243</h4>
                                        <ul class="list list-unstyled mb-0">
                                            <li>生成日期: <span class="font-weight-semibold">2020年5月30日</span></li>
                                            <li>到期日期: <span class="font-weight-semibold">2020年6月30日</span></li>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="d-md-flex flex-md-wrap">
                            <div class="mb-4 mb-md-2 text-left"> <span class="text-muted">Invoice To:</span>
                                <ul class="list list-unstyled mb-0">
                                    <li>
                                        <h5 class="my-2">涂聚文 Geovin Du</h5>
                                    </li>
                                    <li><span class="font-weight-semibold">缔友计算机信息技术有限公司</span></li>
                                    <li>东晓大街</li>
                                    <li>布心路3008号</li>
                                    <li>香港</li>
                                    <li>234 456 5678</li>
                                    <li><a href="#" data-abc="true">geovindu@163.com</a></li>
                                </ul>
                            </div>
                            <div class="mb-2 ml-auto"> <span class="text-muted">付款明细:</span>
                                <div class="d-flex flex-wrap wmin-md-400">
                                    <ul class="list list-unstyled mb-0 text-left">
                                        <li>
                                            <h5 class="my-2">应付款总额:</h5>
                                        </li>
                                        <li>开户银行名称:</li>
                                        <li>国家地区:</li>
                                        <li>城市:</li>
                                        <li>地址:</li>
                                        <li>IBAN:</li>
                                        <li>SWIFT code:</li>
                                    </ul>
                                    <ul class="list list-unstyled text-right mb-0 ml-auto">
                                        <li>
                                            <h5 class="font-weight-semibold my-2">$1,090</h5>
                                        </li>
                                        <li><span class="font-weight-semibold">Hong Kong Bank</span></li>
                                        <li>Hong Kong</li>
                                        <li>Thurnung street, 21</li>
                                        <li>New standard</li>
                                        <li><span class="font-weight-semibold">98574959485</span></li>
                                        <li><span class="font-weight-semibold">BHDHD98273BER</span></li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="table-responsive">
                        <table class="table table-lg">
                            <thead>
                                <tr>
                                    <th>Description</th>
                                    <th>Rate</th>
                                    <th>Hours</th>
                                    <th>Total</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td>
                                        <h6 class="mb-0">Arts and design template</h6> <span class="text-muted">in
                                            reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
                                            pariatur.Duis aute irure dolor in reprehenderit</span >
                                    </td>
                                    <td>$120</td>
                                    <td>180</td>
                                    <td><span class="font-weight-semibold">$300</span></td>
                                </tr>
                                <tr>
                                    <td>
                                        <h6 class="mb-0">Template for desnging the arts</h6> <span class="text-muted">Lorem
                                            ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor</span>
                                    </td>
                                    <td>$140</td>
                                    <td>100</td>
                                    <td><span class="font-weight-semibold">$240</span></td>
                                </tr>
                                <tr>
                                    <td>
                                        <h6 class="mb-0">Technical support international</h6> <span class="text-muted">Lorem
                                            ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor</span>
                                    </td>
                                    <td>$250</td>
                                    <td>$250</td>
                                    <td><span class="font-weight-semibold">$500</span></td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                    <div class="card-body">
                        <div class="d-md-flex flex-md-wrap">
                            <div class="pt-2 mb-3 wmin-md-400 ml-auto">
                                <h6 class="mb-3 text-left">Total due</h6>
                                <div class="table-responsive">
                                    <table class="table">
                                        <tbody>
                                            <tr>
                                                <th class="text-left">Subtotal:</th>
                                                <td class="text-right">$1,090</td>
                                            </tr>
                                            <tr>
                                                <th class="text-left">Tax: <span class="font-weight-normal">(25%)</span></th>
                                                <td class="text-right">$27</td>
                                            </tr>
                                            <tr>
                                                <th class="text-left">Total:</th>
                                                <td class="text-right text-primary">
                                                    <h5 class="font-weight-semibold">$1,160</h5>
                                                </td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </div>
                                <div class="text-right mt-3"> <button type="button" class="btn btn-primary"><b><i class="fa fa-paper-plane-o mr-1"></i></b>
                                        Send invoice</button> </div>
                            </div>
                        </div>
                    </div>
                    <div class="card-footer"> <span class="text-muted">Lorem ipsum dolor sit amet, consectetur
                            adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim
                            ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
                            consequat.Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
                            fugiat nulla pariatur.Duis aute irure dolor in reprehenderit</span> </div>
                </div>
            </div>
        </div>
    </div>
</body>
 
</html>

  

 

pdf.js:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
window.onload = function () {
    document.getElementById("download")
        .addEventListener("click", () => {
            const invoice = this.document.getElementById("invoice");
            console.log(invoice);
            console.log(window);
            //设置
            var opt = {
                 
               /* margin:{
                    top: 80,
                    bottom: 60,
                    left: 40
                    //width: 722
                },*/
                setFontSize:0.1,//10
                setFont:'times',
                setFontType:'italic',
                filename: 'geovindu.pdf',
                image: { type: 'jpeg', quality: 0.98 },
                html2canvas: { scale: 2 },             
                //jsPDF: { unit: 'in', format: 'letter', orientation: 'portrait' } //https://github.com/eKoopmans/html2pdf.js  mm, a4
                //https://rawgit.com/MrRio/jsPDF/master/docs/jsPDF.html
                //https://github.com/niklasvh/html2canvas
                //https://github.com/stefanpenner/es6-promise
                //http://mrrio.github.io/jsPDF/examples/basic.html
                //https://github.com/MrRio/jsPDF https://github.com/parallax/jsPDF
                //jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' }
                jsPDF:{
                        orientation: 'portrait',
                        unit: 'pt',//"pt" (points), "mm", "cm", "in", "px", "pc", "em" or "ex".
                        format: 'a4',
                        putOnlyUsedFonts:true,
                        floatPrecision: 16 // or "smart", default is 16
                     }
            };
            html2pdf().from(invoice).set(opt).save();
        })
}

  

 

posted @   ®Geovin Du Dream Park™  阅读(46)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
历史上的今天:
2011-11-21 CSS DIV大图片右上角叠加小图片
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示