├── LICENSE
├── README.md
├── jquery-version
├── custom.css
├── custom.css.map
├── custom.js
├── custom.min.css
├── custom.min.css.map
├── custom.scss
├── custom2.css
├── index.html
├── js.png
├── receipt.html
└── wsp.png
└── js-version
├── custom.css
├── custom.css.map
├── custom.js
├── custom.min.css
├── custom.min.css.map
├── custom.scss
├── custom2.css
├── index.html
├── js.png
├── receipt.html
└── wsp.png
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 WebStylePress
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # HTML to PDF using JavaScript Only
2 | HTML to PDF using JS Only
3 |
4 | YouTube Tutorial
5 |
6 | https://youtu.be/DV2tAG5E-F0
7 |
--------------------------------------------------------------------------------
/jquery-version/custom.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin-top: 40px;
3 | font-size: 22px;
4 | }
5 |
6 | #ignore {
7 | background-color: #eee;
8 | }
9 |
10 | #btn {
11 | margin-top: 20px;
12 | }
13 |
14 | #content img {
15 | max-width: 200px;
16 | }/*# sourceMappingURL=custom.css.map */
--------------------------------------------------------------------------------
/jquery-version/custom.css.map:
--------------------------------------------------------------------------------
1 | {"version":3,"sources":["custom.scss","custom.css"],"names":[],"mappings":"AAAA;EACE,gBAAA;EACA,eAAA;ACCF;;ADEA;EAAU,sBAAA;ACEV;;ADAA;EAAO,gBAAA;ACIP;;ADFA;EAAe,gBAAA;ACMf","file":"custom.css"}
--------------------------------------------------------------------------------
/jquery-version/custom.js:
--------------------------------------------------------------------------------
1 | jQuery(document).ready(function () {
2 | //////////////
3 | //////////////
4 | $('#btn-print').click(function () {
5 | // window.print();
6 |
7 | let wspFrame = document.getElementById('frame').contentWindow;
8 | wspFrame.focus();
9 | wspFrame.print();
10 | });
11 | //////////////
12 | //////////////
13 |
14 | $('#btn-one').click(function () {
15 | html2canvas(document.querySelector('#content')).then((canvas) => {
16 | let base64image = canvas.toDataURL('image/png');
17 | // console.log(base64image);
18 | let pdf = new jsPDF('p', 'px', [1600, 1131]);
19 | pdf.addImage(base64image, 'PNG', 15, 15, 1110, 360);
20 | pdf.save('webtylepress-two.pdf');
21 | });
22 | });
23 | //////////////
24 | //////////////
25 | $('#btn-two').click(function () {
26 | html2canvas(
27 | document
28 | .querySelector('iframe')
29 | .contentWindow.document.querySelector('.receipt-wrap'),
30 | ).then((canvas) => {
31 | let base64image = canvas.toDataURL('image/png');
32 | // console.log(base64image);
33 | let pdf = new jsPDF('p', 'px', [1600, 1131]);
34 | pdf.addImage(base64image, 'PNG', 15, 15, 1140, 966);
35 | pdf.save('webtylepress-receipt.pdf');
36 | });
37 | });
38 | //////////////
39 | //////////////
40 | });
41 |
--------------------------------------------------------------------------------
/jquery-version/custom.min.css:
--------------------------------------------------------------------------------
1 | body{margin-top:40px;font-size:22px}#ignore{background-color:#eee}#btn{margin-top:20px}#content img{max-width:200px}/*# sourceMappingURL=custom.min.css.map */
--------------------------------------------------------------------------------
/jquery-version/custom.min.css.map:
--------------------------------------------------------------------------------
1 | {"version":3,"sources":["custom.scss"],"names":[],"mappings":"AAAA,KACE,eAAA,CACA,cAAA,CAGF,QAAA,qBAAA,CAEA,KAAA,eAAA,CAEA,aAAA,eAAA","file":"custom.min.css"}
--------------------------------------------------------------------------------
/jquery-version/custom.scss:
--------------------------------------------------------------------------------
1 | body{
2 | margin-top: 40px;
3 | font-size: 22px;
4 | }
5 |
6 | #ignore { background-color: #eee; }
7 |
8 | #btn { margin-top: 20px; }
9 |
10 | #content img { max-width: 200px; }
--------------------------------------------------------------------------------
/jquery-version/custom2.css:
--------------------------------------------------------------------------------
1 | body,
2 | * {
3 | color-adjust: exact !important;
4 | -webkit-print-color-adjust: exact !important;
5 | print-color-adjust: exact !important;
6 | }
7 |
8 | .text-danger strong {
9 | color: #006fb3;
10 | }
11 | .receipt-main {
12 | background: #ffffff none repeat scroll 0 0;
13 | border-bottom: 12px solid #333333;
14 | border-right: 1px solid #ccc;
15 | border-left: 1px solid #ccc;
16 | border-top: 12px solid #006fb3;
17 | margin-top: 50px;
18 | margin-bottom: 50px;
19 | padding: 40px 30px !important;
20 | position: relative;
21 | color: #333333;
22 | font-family: open sans;
23 | }
24 | .receipt-main p {
25 | color: #333333;
26 | font-family: open sans;
27 | line-height: 1.42857;
28 | }
29 | .receipt-footer h1 {
30 | font-size: 15px;
31 | font-weight: 400 !important;
32 | margin: 0 !important;
33 | }
34 | .receipt-main::after {
35 | background: #414143 none repeat scroll 0 0;
36 | content: '';
37 | height: 5px;
38 | left: 0;
39 | position: absolute;
40 | right: 0;
41 | top: -13px;
42 | }
43 | .receipt-main thead {
44 | background: #414143 none repeat scroll 0 0;
45 | }
46 |
47 | .receipt-main th,
48 | .receipt-main thead tr {
49 | background-color: #414143;
50 | }
51 |
52 | .receipt-main thead th {
53 | color: #fff;
54 | }
55 |
56 | .receipt-right h5 {
57 | font-size: 16px;
58 | font-weight: bold;
59 | margin: 0 0 7px 0;
60 | }
61 | .receipt-right p {
62 | font-size: 13px;
63 | margin: 0px;
64 | }
65 | .receipt-right p i {
66 | text-align: center;
67 | width: 18px;
68 | }
69 | .receipt-main td {
70 | padding: 9px 20px !important;
71 | }
72 | .receipt-main th {
73 | padding: 13px 20px !important;
74 | }
75 | .receipt-main td {
76 | font-size: 14px;
77 | font-weight: initial !important;
78 | }
79 | .receipt-main td p:last-child {
80 | margin: 0;
81 | padding: 0;
82 | }
83 | .receipt-main td h2 {
84 | font-size: 20px;
85 | font-weight: 900;
86 | margin: 0;
87 | text-transform: uppercase;
88 | }
89 | .receipt-header-mid .receipt-left h1 {
90 | font-weight: 100;
91 | margin: 34px 0 0;
92 | text-align: right;
93 | text-transform: uppercase;
94 | }
95 | .receipt-header-mid {
96 | margin: 24px 0;
97 | overflow: hidden;
98 | }
99 |
100 | #container {
101 | background-color: #dcdcdc;
102 | }
103 |
104 | @media print {
105 | .receipt-main thead th {
106 | color: #333;
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/jquery-version/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
10 | WebStylePress
11 |
15 |
16 |
17 |
18 |
19 |
20 |
Generate & Download PDF From Page Section Using JS
23 |
24 |
Click at buttons below to generate PDF and
26 | download it using only JavaScript . We can
27 | Generate PDF from whole page. We can target class or
28 | ID and generate PDF from only a section in page -
29 | a part of page.
31 |
32 |
33 |
34 |
35 |
36 |
Print & Generate PDF
39 |
40 |
Download PDF (With Styles & Images / Same Page)
43 |
44 |
Generate PDF From iFrame
47 |
48 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
65 |
66 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/jquery-version/js.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webstylepress/HTML-to-PDF-using-JS-Only/2e8d01f3ab3f2a23b98ab1a9da201d7f7c80af46/jquery-version/js.png
--------------------------------------------------------------------------------
/jquery-version/receipt.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
10 | WebStylePress
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
31 |
32 |
33 |
34 |
35 |
WebStylePress
36 |
+00 00000-0000
37 |
info@sitename.com
38 |
United States
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
WebStylePress
49 |
Mobile : +00 00000-0000
50 |
Email : info@sitename.com
51 |
Address : United States
52 |
53 |
54 |
58 |
59 |
Receipt
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 | Description
71 | Amount
72 |
73 |
74 |
75 |
76 | Payment for August 2022
77 | 15,000/-
78 |
79 |
80 | Payment for June 2022
81 | 6,00/-
82 |
83 |
84 | Payment for May 2022
85 | 35,00/-
86 |
87 |
88 |
89 |
90 | Total Amount:
91 |
92 |
93 | Late Fees:
94 |
95 |
96 | Payable Amount:
97 |
98 |
99 | Balance Due:
100 |
101 |
102 |
103 |
104 | 65,500/-
105 |
106 |
107 | 500/-
108 |
109 |
110 | 1300/-
111 |
112 |
113 | 9500/-
114 |
115 |
116 |
117 |
118 | Total:
121 | 31,566/-
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
Date : 15 Nov 2022
135 |
Thank you for your business!
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
--------------------------------------------------------------------------------
/jquery-version/wsp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webstylepress/HTML-to-PDF-using-JS-Only/2e8d01f3ab3f2a23b98ab1a9da201d7f7c80af46/jquery-version/wsp.png
--------------------------------------------------------------------------------
/js-version/custom.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin-top: 40px;
3 | font-size: 22px;
4 | }
5 |
6 | #ignore {
7 | background-color: #eee;
8 | }
9 |
10 | #btn {
11 | margin-top: 20px;
12 | }
13 |
14 | #content img {
15 | max-width: 200px;
16 | }/*# sourceMappingURL=custom.css.map */
--------------------------------------------------------------------------------
/js-version/custom.css.map:
--------------------------------------------------------------------------------
1 | {"version":3,"sources":["custom.scss","custom.css"],"names":[],"mappings":"AAAA;EACE,gBAAA;EACA,eAAA;ACCF;;ADEA;EAAU,sBAAA;ACEV;;ADAA;EAAO,gBAAA;ACIP;;ADFA;EAAe,gBAAA;ACMf","file":"custom.css"}
--------------------------------------------------------------------------------
/js-version/custom.js:
--------------------------------------------------------------------------------
1 | document.addEventListener('DOMContentLoaded', function () {
2 | //////////////
3 | //////////////
4 | document.querySelector('#btn-print').addEventListener('click', function () {
5 | // window.print();
6 |
7 | let wspFrame = document.getElementById('frame').contentWindow;
8 | wspFrame.focus();
9 | wspFrame.print();
10 | });
11 | //////////////
12 | //////////////
13 |
14 | document.querySelector('#btn-one').addEventListener('click', function () {
15 | html2canvas(document.querySelector('#content')).then((canvas) => {
16 | let base64image = canvas.toDataURL('image/png');
17 | // console.log(base64image);
18 | let pdf = new jsPDF('p', 'px', [1600, 1131]);
19 | pdf.addImage(base64image, 'PNG', 15, 15, 1110, 360);
20 | pdf.save('webtylepress-two.pdf');
21 | });
22 | });
23 | //////////////
24 | //////////////
25 | document.querySelector('#btn-two').addEventListener('click', function () {
26 | html2canvas(
27 | document
28 | .querySelector('iframe')
29 | .contentWindow.document.querySelector('.receipt-wrap'),
30 | ).then((canvas) => {
31 | let base64image = canvas.toDataURL('image/png');
32 | // console.log(base64image);
33 | let pdf = new jsPDF('p', 'px', [1600, 1131]);
34 | pdf.addImage(base64image, 'PNG', 15, 15, 1140, 966);
35 | pdf.save('webtylepress-receipt.pdf');
36 | });
37 | });
38 | //////////////
39 | //////////////
40 | });
41 |
--------------------------------------------------------------------------------
/js-version/custom.min.css:
--------------------------------------------------------------------------------
1 | body{margin-top:40px;font-size:22px}#ignore{background-color:#eee}#btn{margin-top:20px}#content img{max-width:200px}/*# sourceMappingURL=custom.min.css.map */
--------------------------------------------------------------------------------
/js-version/custom.min.css.map:
--------------------------------------------------------------------------------
1 | {"version":3,"sources":["custom.scss"],"names":[],"mappings":"AAAA,KACE,eAAA,CACA,cAAA,CAGF,QAAA,qBAAA,CAEA,KAAA,eAAA,CAEA,aAAA,eAAA","file":"custom.min.css"}
--------------------------------------------------------------------------------
/js-version/custom.scss:
--------------------------------------------------------------------------------
1 | body{
2 | margin-top: 40px;
3 | font-size: 22px;
4 | }
5 |
6 | #ignore { background-color: #eee; }
7 |
8 | #btn { margin-top: 20px; }
9 |
10 | #content img { max-width: 200px; }
--------------------------------------------------------------------------------
/js-version/custom2.css:
--------------------------------------------------------------------------------
1 | body,
2 | * {
3 | color-adjust: exact !important;
4 | -webkit-print-color-adjust: exact !important;
5 | print-color-adjust: exact !important;
6 | }
7 |
8 | .text-danger strong {
9 | color: #006fb3;
10 | }
11 | .receipt-main {
12 | background: #ffffff none repeat scroll 0 0;
13 | border-bottom: 12px solid #333333;
14 | border-right: 1px solid #ccc;
15 | border-left: 1px solid #ccc;
16 | border-top: 12px solid #006fb3;
17 | margin-top: 50px;
18 | margin-bottom: 50px;
19 | padding: 40px 30px !important;
20 | position: relative;
21 | color: #333333;
22 | font-family: open sans;
23 | }
24 | .receipt-main p {
25 | color: #333333;
26 | font-family: open sans;
27 | line-height: 1.42857;
28 | }
29 | .receipt-footer h1 {
30 | font-size: 15px;
31 | font-weight: 400 !important;
32 | margin: 0 !important;
33 | }
34 | .receipt-main::after {
35 | background: #414143 none repeat scroll 0 0;
36 | content: '';
37 | height: 5px;
38 | left: 0;
39 | position: absolute;
40 | right: 0;
41 | top: -13px;
42 | }
43 | .receipt-main thead {
44 | background: #414143 none repeat scroll 0 0;
45 | }
46 |
47 | .receipt-main th,
48 | .receipt-main thead tr {
49 | background-color: #414143;
50 | }
51 |
52 | .receipt-main thead th {
53 | color: #fff;
54 | }
55 |
56 | .receipt-right h5 {
57 | font-size: 16px;
58 | font-weight: bold;
59 | margin: 0 0 7px 0;
60 | }
61 | .receipt-right p {
62 | font-size: 13px;
63 | margin: 0px;
64 | }
65 | .receipt-right p i {
66 | text-align: center;
67 | width: 18px;
68 | }
69 | .receipt-main td {
70 | padding: 9px 20px !important;
71 | }
72 | .receipt-main th {
73 | padding: 13px 20px !important;
74 | }
75 | .receipt-main td {
76 | font-size: 14px;
77 | font-weight: initial !important;
78 | }
79 | .receipt-main td p:last-child {
80 | margin: 0;
81 | padding: 0;
82 | }
83 | .receipt-main td h2 {
84 | font-size: 20px;
85 | font-weight: 900;
86 | margin: 0;
87 | text-transform: uppercase;
88 | }
89 | .receipt-header-mid .receipt-left h1 {
90 | font-weight: 100;
91 | margin: 34px 0 0;
92 | text-align: right;
93 | text-transform: uppercase;
94 | }
95 | .receipt-header-mid {
96 | margin: 24px 0;
97 | overflow: hidden;
98 | }
99 |
100 | #container {
101 | background-color: #dcdcdc;
102 | }
103 |
104 | @media print {
105 | .receipt-main thead th {
106 | color: #333;
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/js-version/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
10 | WebStylePress
11 |
15 |
16 |
17 |
18 |
19 |
20 |
Generate & Download PDF From Page Section Using JS
23 |
24 |
Click at buttons below to generate PDF and
26 | download it using only JavaScript . We can
27 | Generate PDF from whole page. We can target class or
28 | ID and generate PDF from only a section in page -
29 | a part of page.
31 |
32 |
33 |
34 |
35 |
36 |
Print & Generate PDF
39 |
40 |
Download PDF (With Styles & Images / Same Page)
43 |
44 |
Generate PDF From iFrame
47 |
48 |
53 |
54 |
55 |
56 |
57 |
63 |
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/js-version/js.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webstylepress/HTML-to-PDF-using-JS-Only/2e8d01f3ab3f2a23b98ab1a9da201d7f7c80af46/js-version/js.png
--------------------------------------------------------------------------------
/js-version/receipt.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
10 | WebStylePress
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
31 |
32 |
33 |
34 |
35 |
WebStylePress
36 |
+00 00000-0000
37 |
info@sitename.com
38 |
United States
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
WebStylePress
49 |
Mobile : +00 00000-0000
50 |
Email : info@sitename.com
51 |
Address : United States
52 |
53 |
54 |
58 |
59 |
Receipt
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 | Description
71 | Amount
72 |
73 |
74 |
75 |
76 | Payment for August 2022
77 | 15,000/-
78 |
79 |
80 | Payment for June 2022
81 | 6,00/-
82 |
83 |
84 | Payment for May 2022
85 | 35,00/-
86 |
87 |
88 |
89 |
90 | Total Amount:
91 |
92 |
93 | Late Fees:
94 |
95 |
96 | Payable Amount:
97 |
98 |
99 | Balance Due:
100 |
101 |
102 |
103 |
104 | 65,500/-
105 |
106 |
107 | 500/-
108 |
109 |
110 | 1300/-
111 |
112 |
113 | 9500/-
114 |
115 |
116 |
117 |
118 | Total:
121 | 31,566/-
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
Date : 15 Nov 2022
135 |
Thank you for your business!
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
--------------------------------------------------------------------------------
/js-version/wsp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/webstylepress/HTML-to-PDF-using-JS-Only/2e8d01f3ab3f2a23b98ab1a9da201d7f7c80af46/js-version/wsp.png
--------------------------------------------------------------------------------