├── .github
└── ISSUE_TEMPLATE
│ ├── bug_report.md
│ └── feature_request.md
├── .gitignore
├── .npmignore
├── LICENSE
├── README.md
├── babel.config.js
├── documentation
├── api.md
├── assets.md
├── chunks.md
├── content.md
├── creating-pages.md
├── headers-footers.md
├── lists.md
├── real-time.md
└── remote-api.md
├── examples
├── README.md
├── as-a-service
│ ├── client.html
│ ├── readme.md
│ └── server.js
├── assets
│ ├── README.md
│ ├── img
│ │ ├── pdftron.png
│ │ └── pdftron2.png
│ └── index.js
├── chunks
│ ├── README.md
│ ├── index.js
│ └── src
│ │ ├── index.html
│ │ ├── index.scss
│ │ └── myChunk.html
├── dynamic-content
│ ├── README.md
│ ├── index.js
│ └── src
│ │ ├── index.html
│ │ └── style.scss
├── files-as-source
│ ├── README.md
│ ├── index.js
│ └── src
│ │ ├── index.html
│ │ └── index.scss
├── function-to-pdf
│ ├── README.md
│ └── index.js
├── headers-footers
│ ├── README.md
│ ├── index.js
│ └── src
│ │ ├── footer.html
│ │ ├── header.html
│ │ ├── index.html
│ │ └── style.scss
├── html-to-pdf-basic
│ ├── README.md
│ └── index.js
├── javascript
│ ├── README.md
│ ├── index.js
│ └── src
│ │ ├── cool-rendering.js
│ │ ├── index.html
│ │ └── style.scss
├── page-numbers
│ ├── index.html
│ ├── index.js
│ ├── index.scss
│ └── readme.md
├── react-to-pdf
│ ├── README.md
│ └── index.js
├── real-time
│ ├── README.md
│ ├── index.js
│ ├── options.js
│ └── src
│ │ ├── index.html
│ │ └── index.scss
└── remote-source
│ ├── README.md
│ └── index.js
├── package.json
├── src
├── index.js
├── server.js
├── styles
│ └── index.css
├── util
│ ├── clean-html.js
│ ├── copy-dir.js
│ ├── custom-require.js
│ ├── delete-dir.js
│ ├── does-file-exist.js
│ ├── ensure-exists.js
│ ├── ensure-page.js
│ ├── get-asset-source.js
│ ├── get-content.js
│ ├── get-css-src.js
│ ├── get-custom-css.js
│ ├── get-custom-scripts.js
│ ├── get-html-from-source.js
│ ├── get-options.js
│ ├── get-render-type.js
│ ├── get-script-src.js
│ ├── inject-custom-scripts.js
│ ├── inject-header-footer.js
│ ├── inject-styles.js
│ ├── insert-content.js
│ ├── listen-to-changes.js
│ ├── print-pdf.js
│ ├── react-to-html.js
│ ├── read-file.js
│ ├── replace-page-numbers.js
│ ├── to-absolute.js
│ ├── type-check.js
│ ├── verify-page.js
│ └── write-file.js
└── writer.js
├── test
├── assets.js
├── assets
│ ├── content.json
│ ├── index.html
│ ├── options.js
│ ├── script.js
│ ├── style.scss
│ └── temp.txt
├── clean-html.js
├── content.js
├── html.js
├── main.js
├── other.js
├── pageClass.js
├── realtime.js
├── remote.js
├── scripts.js
└── style.js
└── webpack.config.js
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 |
5 | ---
6 |
7 | **Describe the bug**
8 | A clear and concise description of what the bug is.
9 |
10 | **To Reproduce**
11 | Steps to reproduce the behavior, include code or a sample repo if possible:
12 | ...
13 |
14 |
15 | **Expected behavior**
16 | A clear and concise description of what you expected to happen.
17 |
18 | **Screenshots**
19 | If applicable, add screenshots to help explain your problem.
20 |
21 | **Desktop (please complete the following information):**
22 | - OS: [e.g. iOS]
23 | - Browser [e.g. chrome, safari]
24 | - Version [e.g. 22]
25 |
26 | **Additional context**
27 | Add any other context about the problem here.
28 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 |
5 | ---
6 |
7 | **Is your feature request related to a problem? Please describe.**
8 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
9 |
10 | **Describe the solution you'd like**
11 | A clear and concise description of what you want to happen.
12 |
13 | **Describe alternatives you've considered**
14 | A clear and concise description of any alternative solutions or features you've considered.
15 |
16 | **Additional context**
17 | Add any other context or screenshots about the feature request here.
18 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 |
8 | dist/
9 | outputs/
10 | pages/
11 | test-examples/
12 | examples/template/
13 | package-lock.json
14 | test/assets/temp.txt
15 | # Runtime data
16 | pids
17 | *.pid
18 | *.seed
19 | *.pid.lock
20 |
21 | # Directory for instrumented libs generated by jscoverage/JSCover
22 | lib-cov
23 |
24 | # Coverage directory used by tools like istanbul
25 | coverage
26 |
27 | # nyc test coverage
28 | .nyc_output
29 |
30 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
31 | .grunt
32 |
33 | # Bower dependency directory (https://bower.io/)
34 | bower_components
35 |
36 | # node-waf configuration
37 | .lock-wscript
38 |
39 | # Compiled binary addons (https://nodejs.org/api/addons.html)
40 | build/Release
41 |
42 | # Dependency directories
43 | node_modules/
44 | jspm_packages/
45 |
46 | # TypeScript v1 declaration files
47 | typings/
48 |
49 | # Optional npm cache directory
50 | .npm
51 |
52 | # Optional eslint cache
53 | .eslintcache
54 |
55 | # Optional REPL history
56 | .node_repl_history
57 |
58 | # Output of 'npm pack'
59 | *.tgz
60 |
61 | # Yarn Integrity file
62 | .yarn-integrity
63 |
64 | # dotenv environment variables file
65 | .env
66 |
67 | # next.js build output
68 | .next
69 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | src
2 | .babelrc
3 | webpack.config.js
4 | outputs
5 | example-pages
6 | tests
7 | example-projects
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU AFFERO GENERAL PUBLIC LICENSE
2 | Version 3, 19 November 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU Affero General Public License is a free, copyleft license for
11 | software and other kinds of works, specifically designed to ensure
12 | cooperation with the community in the case of network server software.
13 |
14 | The licenses for most software and other practical works are designed
15 | to take away your freedom to share and change the works. By contrast,
16 | our General Public Licenses are intended to guarantee your freedom to
17 | share and change all versions of a program--to make sure it remains free
18 | software for all its users.
19 |
20 | When we speak of free software, we are referring to freedom, not
21 | price. Our General Public Licenses are designed to make sure that you
22 | have the freedom to distribute copies of free software (and charge for
23 | them if you wish), that you receive source code or can get it if you
24 | want it, that you can change the software or use pieces of it in new
25 | free programs, and that you know you can do these things.
26 |
27 | Developers that use our General Public Licenses protect your rights
28 | with two steps: (1) assert copyright on the software, and (2) offer
29 | you this License which gives you legal permission to copy, distribute
30 | and/or modify the software.
31 |
32 | A secondary benefit of defending all users' freedom is that
33 | improvements made in alternate versions of the program, if they
34 | receive widespread use, become available for other developers to
35 | incorporate. Many developers of free software are heartened and
36 | encouraged by the resulting cooperation. However, in the case of
37 | software used on network servers, this result may fail to come about.
38 | The GNU General Public License permits making a modified version and
39 | letting the public access it on a server without ever releasing its
40 | source code to the public.
41 |
42 | The GNU Affero General Public License is designed specifically to
43 | ensure that, in such cases, the modified source code becomes available
44 | to the community. It requires the operator of a network server to
45 | provide the source code of the modified version running there to the
46 | users of that server. Therefore, public use of a modified version, on
47 | a publicly accessible server, gives the public access to the source
48 | code of the modified version.
49 |
50 | An older license, called the Affero General Public License and
51 | published by Affero, was designed to accomplish similar goals. This is
52 | a different license, not a version of the Affero GPL, but Affero has
53 | released a new version of the Affero GPL which permits relicensing under
54 | this license.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | TERMS AND CONDITIONS
60 |
61 | 0. Definitions.
62 |
63 | "This License" refers to version 3 of the GNU Affero General Public License.
64 |
65 | "Copyright" also means copyright-like laws that apply to other kinds of
66 | works, such as semiconductor masks.
67 |
68 | "The Program" refers to any copyrightable work licensed under this
69 | License. Each licensee is addressed as "you". "Licensees" and
70 | "recipients" may be individuals or organizations.
71 |
72 | To "modify" a work means to copy from or adapt all or part of the work
73 | in a fashion requiring copyright permission, other than the making of an
74 | exact copy. The resulting work is called a "modified version" of the
75 | earlier work or a work "based on" the earlier work.
76 |
77 | A "covered work" means either the unmodified Program or a work based
78 | on the Program.
79 |
80 | To "propagate" a work means to do anything with it that, without
81 | permission, would make you directly or secondarily liable for
82 | infringement under applicable copyright law, except executing it on a
83 | computer or modifying a private copy. Propagation includes copying,
84 | distribution (with or without modification), making available to the
85 | public, and in some countries other activities as well.
86 |
87 | To "convey" a work means any kind of propagation that enables other
88 | parties to make or receive copies. Mere interaction with a user through
89 | a computer network, with no transfer of a copy, is not conveying.
90 |
91 | An interactive user interface displays "Appropriate Legal Notices"
92 | to the extent that it includes a convenient and prominently visible
93 | feature that (1) displays an appropriate copyright notice, and (2)
94 | tells the user that there is no warranty for the work (except to the
95 | extent that warranties are provided), that licensees may convey the
96 | work under this License, and how to view a copy of this License. If
97 | the interface presents a list of user commands or options, such as a
98 | menu, a prominent item in the list meets this criterion.
99 |
100 | 1. Source Code.
101 |
102 | The "source code" for a work means the preferred form of the work
103 | for making modifications to it. "Object code" means any non-source
104 | form of a work.
105 |
106 | A "Standard Interface" means an interface that either is an official
107 | standard defined by a recognized standards body, or, in the case of
108 | interfaces specified for a particular programming language, one that
109 | is widely used among developers working in that language.
110 |
111 | The "System Libraries" of an executable work include anything, other
112 | than the work as a whole, that (a) is included in the normal form of
113 | packaging a Major Component, but which is not part of that Major
114 | Component, and (b) serves only to enable use of the work with that
115 | Major Component, or to implement a Standard Interface for which an
116 | implementation is available to the public in source code form. A
117 | "Major Component", in this context, means a major essential component
118 | (kernel, window system, and so on) of the specific operating system
119 | (if any) on which the executable work runs, or a compiler used to
120 | produce the work, or an object code interpreter used to run it.
121 |
122 | The "Corresponding Source" for a work in object code form means all
123 | the source code needed to generate, install, and (for an executable
124 | work) run the object code and to modify the work, including scripts to
125 | control those activities. However, it does not include the work's
126 | System Libraries, or general-purpose tools or generally available free
127 | programs which are used unmodified in performing those activities but
128 | which are not part of the work. For example, Corresponding Source
129 | includes interface definition files associated with source files for
130 | the work, and the source code for shared libraries and dynamically
131 | linked subprograms that the work is specifically designed to require,
132 | such as by intimate data communication or control flow between those
133 | subprograms and other parts of the work.
134 |
135 | The Corresponding Source need not include anything that users
136 | can regenerate automatically from other parts of the Corresponding
137 | Source.
138 |
139 | The Corresponding Source for a work in source code form is that
140 | same work.
141 |
142 | 2. Basic Permissions.
143 |
144 | All rights granted under this License are granted for the term of
145 | copyright on the Program, and are irrevocable provided the stated
146 | conditions are met. This License explicitly affirms your unlimited
147 | permission to run the unmodified Program. The output from running a
148 | covered work is covered by this License only if the output, given its
149 | content, constitutes a covered work. This License acknowledges your
150 | rights of fair use or other equivalent, as provided by copyright law.
151 |
152 | You may make, run and propagate covered works that you do not
153 | convey, without conditions so long as your license otherwise remains
154 | in force. You may convey covered works to others for the sole purpose
155 | of having them make modifications exclusively for you, or provide you
156 | with facilities for running those works, provided that you comply with
157 | the terms of this License in conveying all material for which you do
158 | not control copyright. Those thus making or running the covered works
159 | for you must do so exclusively on your behalf, under your direction
160 | and control, on terms that prohibit them from making any copies of
161 | your copyrighted material outside their relationship with you.
162 |
163 | Conveying under any other circumstances is permitted solely under
164 | the conditions stated below. Sublicensing is not allowed; section 10
165 | makes it unnecessary.
166 |
167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
168 |
169 | No covered work shall be deemed part of an effective technological
170 | measure under any applicable law fulfilling obligations under article
171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
172 | similar laws prohibiting or restricting circumvention of such
173 | measures.
174 |
175 | When you convey a covered work, you waive any legal power to forbid
176 | circumvention of technological measures to the extent such circumvention
177 | is effected by exercising rights under this License with respect to
178 | the covered work, and you disclaim any intention to limit operation or
179 | modification of the work as a means of enforcing, against the work's
180 | users, your or third parties' legal rights to forbid circumvention of
181 | technological measures.
182 |
183 | 4. Conveying Verbatim Copies.
184 |
185 | You may convey verbatim copies of the Program's source code as you
186 | receive it, in any medium, provided that you conspicuously and
187 | appropriately publish on each copy an appropriate copyright notice;
188 | keep intact all notices stating that this License and any
189 | non-permissive terms added in accord with section 7 apply to the code;
190 | keep intact all notices of the absence of any warranty; and give all
191 | recipients a copy of this License along with the Program.
192 |
193 | You may charge any price or no price for each copy that you convey,
194 | and you may offer support or warranty protection for a fee.
195 |
196 | 5. Conveying Modified Source Versions.
197 |
198 | You may convey a work based on the Program, or the modifications to
199 | produce it from the Program, in the form of source code under the
200 | terms of section 4, provided that you also meet all of these conditions:
201 |
202 | a) The work must carry prominent notices stating that you modified
203 | it, and giving a relevant date.
204 |
205 | b) The work must carry prominent notices stating that it is
206 | released under this License and any conditions added under section
207 | 7. This requirement modifies the requirement in section 4 to
208 | "keep intact all notices".
209 |
210 | c) You must license the entire work, as a whole, under this
211 | License to anyone who comes into possession of a copy. This
212 | License will therefore apply, along with any applicable section 7
213 | additional terms, to the whole of the work, and all its parts,
214 | regardless of how they are packaged. This License gives no
215 | permission to license the work in any other way, but it does not
216 | invalidate such permission if you have separately received it.
217 |
218 | d) If the work has interactive user interfaces, each must display
219 | Appropriate Legal Notices; however, if the Program has interactive
220 | interfaces that do not display Appropriate Legal Notices, your
221 | work need not make them do so.
222 |
223 | A compilation of a covered work with other separate and independent
224 | works, which are not by their nature extensions of the covered work,
225 | and which are not combined with it such as to form a larger program,
226 | in or on a volume of a storage or distribution medium, is called an
227 | "aggregate" if the compilation and its resulting copyright are not
228 | used to limit the access or legal rights of the compilation's users
229 | beyond what the individual works permit. Inclusion of a covered work
230 | in an aggregate does not cause this License to apply to the other
231 | parts of the aggregate.
232 |
233 | 6. Conveying Non-Source Forms.
234 |
235 | You may convey a covered work in object code form under the terms
236 | of sections 4 and 5, provided that you also convey the
237 | machine-readable Corresponding Source under the terms of this License,
238 | in one of these ways:
239 |
240 | a) Convey the object code in, or embodied in, a physical product
241 | (including a physical distribution medium), accompanied by the
242 | Corresponding Source fixed on a durable physical medium
243 | customarily used for software interchange.
244 |
245 | b) Convey the object code in, or embodied in, a physical product
246 | (including a physical distribution medium), accompanied by a
247 | written offer, valid for at least three years and valid for as
248 | long as you offer spare parts or customer support for that product
249 | model, to give anyone who possesses the object code either (1) a
250 | copy of the Corresponding Source for all the software in the
251 | product that is covered by this License, on a durable physical
252 | medium customarily used for software interchange, for a price no
253 | more than your reasonable cost of physically performing this
254 | conveying of source, or (2) access to copy the
255 | Corresponding Source from a network server at no charge.
256 |
257 | c) Convey individual copies of the object code with a copy of the
258 | written offer to provide the Corresponding Source. This
259 | alternative is allowed only occasionally and noncommercially, and
260 | only if you received the object code with such an offer, in accord
261 | with subsection 6b.
262 |
263 | d) Convey the object code by offering access from a designated
264 | place (gratis or for a charge), and offer equivalent access to the
265 | Corresponding Source in the same way through the same place at no
266 | further charge. You need not require recipients to copy the
267 | Corresponding Source along with the object code. If the place to
268 | copy the object code is a network server, the Corresponding Source
269 | may be on a different server (operated by you or a third party)
270 | that supports equivalent copying facilities, provided you maintain
271 | clear directions next to the object code saying where to find the
272 | Corresponding Source. Regardless of what server hosts the
273 | Corresponding Source, you remain obligated to ensure that it is
274 | available for as long as needed to satisfy these requirements.
275 |
276 | e) Convey the object code using peer-to-peer transmission, provided
277 | you inform other peers where the object code and Corresponding
278 | Source of the work are being offered to the general public at no
279 | charge under subsection 6d.
280 |
281 | A separable portion of the object code, whose source code is excluded
282 | from the Corresponding Source as a System Library, need not be
283 | included in conveying the object code work.
284 |
285 | A "User Product" is either (1) a "consumer product", which means any
286 | tangible personal property which is normally used for personal, family,
287 | or household purposes, or (2) anything designed or sold for incorporation
288 | into a dwelling. In determining whether a product is a consumer product,
289 | doubtful cases shall be resolved in favor of coverage. For a particular
290 | product received by a particular user, "normally used" refers to a
291 | typical or common use of that class of product, regardless of the status
292 | of the particular user or of the way in which the particular user
293 | actually uses, or expects or is expected to use, the product. A product
294 | is a consumer product regardless of whether the product has substantial
295 | commercial, industrial or non-consumer uses, unless such uses represent
296 | the only significant mode of use of the product.
297 |
298 | "Installation Information" for a User Product means any methods,
299 | procedures, authorization keys, or other information required to install
300 | and execute modified versions of a covered work in that User Product from
301 | a modified version of its Corresponding Source. The information must
302 | suffice to ensure that the continued functioning of the modified object
303 | code is in no case prevented or interfered with solely because
304 | modification has been made.
305 |
306 | If you convey an object code work under this section in, or with, or
307 | specifically for use in, a User Product, and the conveying occurs as
308 | part of a transaction in which the right of possession and use of the
309 | User Product is transferred to the recipient in perpetuity or for a
310 | fixed term (regardless of how the transaction is characterized), the
311 | Corresponding Source conveyed under this section must be accompanied
312 | by the Installation Information. But this requirement does not apply
313 | if neither you nor any third party retains the ability to install
314 | modified object code on the User Product (for example, the work has
315 | been installed in ROM).
316 |
317 | The requirement to provide Installation Information does not include a
318 | requirement to continue to provide support service, warranty, or updates
319 | for a work that has been modified or installed by the recipient, or for
320 | the User Product in which it has been modified or installed. Access to a
321 | network may be denied when the modification itself materially and
322 | adversely affects the operation of the network or violates the rules and
323 | protocols for communication across the network.
324 |
325 | Corresponding Source conveyed, and Installation Information provided,
326 | in accord with this section must be in a format that is publicly
327 | documented (and with an implementation available to the public in
328 | source code form), and must require no special password or key for
329 | unpacking, reading or copying.
330 |
331 | 7. Additional Terms.
332 |
333 | "Additional permissions" are terms that supplement the terms of this
334 | License by making exceptions from one or more of its conditions.
335 | Additional permissions that are applicable to the entire Program shall
336 | be treated as though they were included in this License, to the extent
337 | that they are valid under applicable law. If additional permissions
338 | apply only to part of the Program, that part may be used separately
339 | under those permissions, but the entire Program remains governed by
340 | this License without regard to the additional permissions.
341 |
342 | When you convey a copy of a covered work, you may at your option
343 | remove any additional permissions from that copy, or from any part of
344 | it. (Additional permissions may be written to require their own
345 | removal in certain cases when you modify the work.) You may place
346 | additional permissions on material, added by you to a covered work,
347 | for which you have or can give appropriate copyright permission.
348 |
349 | Notwithstanding any other provision of this License, for material you
350 | add to a covered work, you may (if authorized by the copyright holders of
351 | that material) supplement the terms of this License with terms:
352 |
353 | a) Disclaiming warranty or limiting liability differently from the
354 | terms of sections 15 and 16 of this License; or
355 |
356 | b) Requiring preservation of specified reasonable legal notices or
357 | author attributions in that material or in the Appropriate Legal
358 | Notices displayed by works containing it; or
359 |
360 | c) Prohibiting misrepresentation of the origin of that material, or
361 | requiring that modified versions of such material be marked in
362 | reasonable ways as different from the original version; or
363 |
364 | d) Limiting the use for publicity purposes of names of licensors or
365 | authors of the material; or
366 |
367 | e) Declining to grant rights under trademark law for use of some
368 | trade names, trademarks, or service marks; or
369 |
370 | f) Requiring indemnification of licensors and authors of that
371 | material by anyone who conveys the material (or modified versions of
372 | it) with contractual assumptions of liability to the recipient, for
373 | any liability that these contractual assumptions directly impose on
374 | those licensors and authors.
375 |
376 | All other non-permissive additional terms are considered "further
377 | restrictions" within the meaning of section 10. If the Program as you
378 | received it, or any part of it, contains a notice stating that it is
379 | governed by this License along with a term that is a further
380 | restriction, you may remove that term. If a license document contains
381 | a further restriction but permits relicensing or conveying under this
382 | License, you may add to a covered work material governed by the terms
383 | of that license document, provided that the further restriction does
384 | not survive such relicensing or conveying.
385 |
386 | If you add terms to a covered work in accord with this section, you
387 | must place, in the relevant source files, a statement of the
388 | additional terms that apply to those files, or a notice indicating
389 | where to find the applicable terms.
390 |
391 | Additional terms, permissive or non-permissive, may be stated in the
392 | form of a separately written license, or stated as exceptions;
393 | the above requirements apply either way.
394 |
395 | 8. Termination.
396 |
397 | You may not propagate or modify a covered work except as expressly
398 | provided under this License. Any attempt otherwise to propagate or
399 | modify it is void, and will automatically terminate your rights under
400 | this License (including any patent licenses granted under the third
401 | paragraph of section 11).
402 |
403 | However, if you cease all violation of this License, then your
404 | license from a particular copyright holder is reinstated (a)
405 | provisionally, unless and until the copyright holder explicitly and
406 | finally terminates your license, and (b) permanently, if the copyright
407 | holder fails to notify you of the violation by some reasonable means
408 | prior to 60 days after the cessation.
409 |
410 | Moreover, your license from a particular copyright holder is
411 | reinstated permanently if the copyright holder notifies you of the
412 | violation by some reasonable means, this is the first time you have
413 | received notice of violation of this License (for any work) from that
414 | copyright holder, and you cure the violation prior to 30 days after
415 | your receipt of the notice.
416 |
417 | Termination of your rights under this section does not terminate the
418 | licenses of parties who have received copies or rights from you under
419 | this License. If your rights have been terminated and not permanently
420 | reinstated, you do not qualify to receive new licenses for the same
421 | material under section 10.
422 |
423 | 9. Acceptance Not Required for Having Copies.
424 |
425 | You are not required to accept this License in order to receive or
426 | run a copy of the Program. Ancillary propagation of a covered work
427 | occurring solely as a consequence of using peer-to-peer transmission
428 | to receive a copy likewise does not require acceptance. However,
429 | nothing other than this License grants you permission to propagate or
430 | modify any covered work. These actions infringe copyright if you do
431 | not accept this License. Therefore, by modifying or propagating a
432 | covered work, you indicate your acceptance of this License to do so.
433 |
434 | 10. Automatic Licensing of Downstream Recipients.
435 |
436 | Each time you convey a covered work, the recipient automatically
437 | receives a license from the original licensors, to run, modify and
438 | propagate that work, subject to this License. You are not responsible
439 | for enforcing compliance by third parties with this License.
440 |
441 | An "entity transaction" is a transaction transferring control of an
442 | organization, or substantially all assets of one, or subdividing an
443 | organization, or merging organizations. If propagation of a covered
444 | work results from an entity transaction, each party to that
445 | transaction who receives a copy of the work also receives whatever
446 | licenses to the work the party's predecessor in interest had or could
447 | give under the previous paragraph, plus a right to possession of the
448 | Corresponding Source of the work from the predecessor in interest, if
449 | the predecessor has it or can get it with reasonable efforts.
450 |
451 | You may not impose any further restrictions on the exercise of the
452 | rights granted or affirmed under this License. For example, you may
453 | not impose a license fee, royalty, or other charge for exercise of
454 | rights granted under this License, and you may not initiate litigation
455 | (including a cross-claim or counterclaim in a lawsuit) alleging that
456 | any patent claim is infringed by making, using, selling, offering for
457 | sale, or importing the Program or any portion of it.
458 |
459 | 11. Patents.
460 |
461 | A "contributor" is a copyright holder who authorizes use under this
462 | License of the Program or a work on which the Program is based. The
463 | work thus licensed is called the contributor's "contributor version".
464 |
465 | A contributor's "essential patent claims" are all patent claims
466 | owned or controlled by the contributor, whether already acquired or
467 | hereafter acquired, that would be infringed by some manner, permitted
468 | by this License, of making, using, or selling its contributor version,
469 | but do not include claims that would be infringed only as a
470 | consequence of further modification of the contributor version. For
471 | purposes of this definition, "control" includes the right to grant
472 | patent sublicenses in a manner consistent with the requirements of
473 | this License.
474 |
475 | Each contributor grants you a non-exclusive, worldwide, royalty-free
476 | patent license under the contributor's essential patent claims, to
477 | make, use, sell, offer for sale, import and otherwise run, modify and
478 | propagate the contents of its contributor version.
479 |
480 | In the following three paragraphs, a "patent license" is any express
481 | agreement or commitment, however denominated, not to enforce a patent
482 | (such as an express permission to practice a patent or covenant not to
483 | sue for patent infringement). To "grant" such a patent license to a
484 | party means to make such an agreement or commitment not to enforce a
485 | patent against the party.
486 |
487 | If you convey a covered work, knowingly relying on a patent license,
488 | and the Corresponding Source of the work is not available for anyone
489 | to copy, free of charge and under the terms of this License, through a
490 | publicly available network server or other readily accessible means,
491 | then you must either (1) cause the Corresponding Source to be so
492 | available, or (2) arrange to deprive yourself of the benefit of the
493 | patent license for this particular work, or (3) arrange, in a manner
494 | consistent with the requirements of this License, to extend the patent
495 | license to downstream recipients. "Knowingly relying" means you have
496 | actual knowledge that, but for the patent license, your conveying the
497 | covered work in a country, or your recipient's use of the covered work
498 | in a country, would infringe one or more identifiable patents in that
499 | country that you have reason to believe are valid.
500 |
501 | If, pursuant to or in connection with a single transaction or
502 | arrangement, you convey, or propagate by procuring conveyance of, a
503 | covered work, and grant a patent license to some of the parties
504 | receiving the covered work authorizing them to use, propagate, modify
505 | or convey a specific copy of the covered work, then the patent license
506 | you grant is automatically extended to all recipients of the covered
507 | work and works based on it.
508 |
509 | A patent license is "discriminatory" if it does not include within
510 | the scope of its coverage, prohibits the exercise of, or is
511 | conditioned on the non-exercise of one or more of the rights that are
512 | specifically granted under this License. You may not convey a covered
513 | work if you are a party to an arrangement with a third party that is
514 | in the business of distributing software, under which you make payment
515 | to the third party based on the extent of your activity of conveying
516 | the work, and under which the third party grants, to any of the
517 | parties who would receive the covered work from you, a discriminatory
518 | patent license (a) in connection with copies of the covered work
519 | conveyed by you (or copies made from those copies), or (b) primarily
520 | for and in connection with specific products or compilations that
521 | contain the covered work, unless you entered into that arrangement,
522 | or that patent license was granted, prior to 28 March 2007.
523 |
524 | Nothing in this License shall be construed as excluding or limiting
525 | any implied license or other defenses to infringement that may
526 | otherwise be available to you under applicable patent law.
527 |
528 | 12. No Surrender of Others' Freedom.
529 |
530 | If conditions are imposed on you (whether by court order, agreement or
531 | otherwise) that contradict the conditions of this License, they do not
532 | excuse you from the conditions of this License. If you cannot convey a
533 | covered work so as to satisfy simultaneously your obligations under this
534 | License and any other pertinent obligations, then as a consequence you may
535 | not convey it at all. For example, if you agree to terms that obligate you
536 | to collect a royalty for further conveying from those to whom you convey
537 | the Program, the only way you could satisfy both those terms and this
538 | License would be to refrain entirely from conveying the Program.
539 |
540 | 13. Remote Network Interaction; Use with the GNU General Public License.
541 |
542 | Notwithstanding any other provision of this License, if you modify the
543 | Program, your modified version must prominently offer all users
544 | interacting with it remotely through a computer network (if your version
545 | supports such interaction) an opportunity to receive the Corresponding
546 | Source of your version by providing access to the Corresponding Source
547 | from a network server at no charge, through some standard or customary
548 | means of facilitating copying of software. This Corresponding Source
549 | shall include the Corresponding Source for any work covered by version 3
550 | of the GNU General Public License that is incorporated pursuant to the
551 | following paragraph.
552 |
553 | Notwithstanding any other provision of this License, you have
554 | permission to link or combine any covered work with a work licensed
555 | under version 3 of the GNU General Public License into a single
556 | combined work, and to convey the resulting work. The terms of this
557 | License will continue to apply to the part which is the covered work,
558 | but the work with which it is combined will remain governed by version
559 | 3 of the GNU General Public License.
560 |
561 | 14. Revised Versions of this License.
562 |
563 | The Free Software Foundation may publish revised and/or new versions of
564 | the GNU Affero General Public License from time to time. Such new versions
565 | will be similar in spirit to the present version, but may differ in detail to
566 | address new problems or concerns.
567 |
568 | Each version is given a distinguishing version number. If the
569 | Program specifies that a certain numbered version of the GNU Affero General
570 | Public License "or any later version" applies to it, you have the
571 | option of following the terms and conditions either of that numbered
572 | version or of any later version published by the Free Software
573 | Foundation. If the Program does not specify a version number of the
574 | GNU Affero General Public License, you may choose any version ever published
575 | by the Free Software Foundation.
576 |
577 | If the Program specifies that a proxy can decide which future
578 | versions of the GNU Affero General Public License can be used, that proxy's
579 | public statement of acceptance of a version permanently authorizes you
580 | to choose that version for the Program.
581 |
582 | Later license versions may give you additional or different
583 | permissions. However, no additional obligations are imposed on any
584 | author or copyright holder as a result of your choosing to follow a
585 | later version.
586 |
587 | 15. Disclaimer of Warranty.
588 |
589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
597 |
598 | 16. Limitation of Liability.
599 |
600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
608 | SUCH DAMAGES.
609 |
610 | 17. Interpretation of Sections 15 and 16.
611 |
612 | If the disclaimer of warranty and limitation of liability provided
613 | above cannot be given local legal effect according to their terms,
614 | reviewing courts shall apply local law that most closely approximates
615 | an absolute waiver of all civil liability in connection with the
616 | Program, unless a warranty or assumption of liability accompanies a
617 | copy of the Program in return for a fee.
618 |
619 | END OF TERMS AND CONDITIONS
620 |
621 | How to Apply These Terms to Your New Programs
622 |
623 | If you develop a new program, and you want it to be of the greatest
624 | possible use to the public, the best way to achieve this is to make it
625 | free software which everyone can redistribute and change under these terms.
626 |
627 | To do so, attach the following notices to the program. It is safest
628 | to attach them to the start of each source file to most effectively
629 | state the exclusion of warranty; and each file should have at least
630 | the "copyright" line and a pointer to where the full notice is found.
631 |
632 |
633 | Copyright (C)
634 |
635 | This program is free software: you can redistribute it and/or modify
636 | it under the terms of the GNU Affero General Public License as published
637 | by the Free Software Foundation, either version 3 of the License, or
638 | (at your option) any later version.
639 |
640 | This program is distributed in the hope that it will be useful,
641 | but WITHOUT ANY WARRANTY; without even the implied warranty of
642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
643 | GNU Affero General Public License for more details.
644 |
645 | You should have received a copy of the GNU Affero General Public License
646 | along with this program. If not, see .
647 |
648 | Also add information on how to contact you by electronic and paper mail.
649 |
650 | If your software can interact with users remotely through a computer
651 | network, you should also make sure that it provides a way for users to
652 | get its source. For example, if your program is a web application, its
653 | interface could display a "Source" link that leads users to an archive
654 | of the code. There are many ways you could offer source, and different
655 | solutions will be better for different programs; see section 13 for the
656 | specific requirements.
657 |
658 | You should also get your employer (if you work as a programmer) or school,
659 | if any, to sign a "copyright disclaimer" for the program, if necessary.
660 | For more information on this, and how to apply and follow the GNU AGPL, see
661 | .
662 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Web to PDF Converter
2 | Easily create beautiful PDFs using your favorite Javascript and CSS framework!
3 |
4 | Created and maintained by [PDFTron](https://pdftron.com).
5 |
6 | **This project is still in development and should not be used in a production environment! It has not been tested in all use cases.**
7 |
8 | **We are very interested in seeing how people use this tool. If you have any questions, comments or would just like to tell us how you're using it, please feel free to open a ticket!**
9 |
10 | ## Features
11 | - 💥 JS is fully supported, meaning you can use your favorite frameworks to generate your PDF.
12 | - 🔄 Comes with a powerful [content replacement](https://github.com/PDFTron/web-to-pdf/tree/master/documentation/content.md) system that allows for dynamic content.
13 | - 🔢 Insert [page numbers](https://github.com/PDFTron/web-to-pdf/tree/master/documentation/creating-pages.md#page-numbers) in your pages dynamically.
14 | - 💃 [Full SCSS support](https://github.com/PDFTron/web-to-pdf/tree/master/documentation/api.md#styles)
15 | - 👸 Support for [headers and footers](https://github.com/PDFTron/web-to-pdf/tree/master/documentation/headers-footers.md)
16 | - 🔗 Support for reusuable [HTML chunks](https://github.com/PDFTron/web-to-pdf/tree/master/documentation/chunks.md)
17 | - 🎥 [Real time mode](https://github.com/PDFTron/web-to-pdf/tree/master/documentation/real-time.md) with hot reloading, meaning you can build your PDF in real time
18 | - 🌏 Support for [rendering remote pages](https://github.com/PDFTron/web-to-pdf/tree/master/documentation/remote-api.md) (You can even inject your own css and js!)
19 | - 🚦 Queueing system so you can render 1000's of PDFs with a single script.
20 | - 👍 Much more!
21 |
22 | ## Roadmap
23 | - Examples (external repos?) of usage with other frameworks
24 | - Splitting of non-list content on page break
25 | - Support for form inputs
26 |
27 | ## Installation
28 | ```
29 | npm i @pdftron/web-to-pdf
30 | ```
31 |
32 | ## Example
33 | ```js
34 | const Renderer = require('@pdftron/web-to-pdf');
35 |
36 | const r = new Renderer({ dirname: __dirname });
37 |
38 | const htmlString = `
39 |
40 |
41 |
42 |
43 |
44 |
45 | Page1: {{myText}}
46 |
47 |
48 |
49 | Page2: Goodbye world!
50 |
51 |
52 |
53 | `;
54 |
55 | r.render({
56 | templateSource: htmlString,
57 | contentSource: {
58 | myText: "Hello world!"
59 | },
60 | outputName: 'example'
61 | });
62 |
63 | // Pdf will be rendered at ./outputs/example.pdf !
64 | ```
65 |
66 | See more examples [here](examples/).
67 |
68 | ## Documentation
69 | - [Creating pages + Dynamic page numbers](https://github.com/PDFTron/web-to-pdf/blob/master/documentation/creating-pages.md)
70 | - [API](https://github.com/PDFTron/web-to-pdf/blob/master/documentation/api.md)
71 | - [Rendering remote pages](https://github.com/PDFTron/web-to-pdf/blob/master/documentation/remote-api.md)
72 | - [Headers and footers](https://github.com/PDFTron/web-to-pdf/blob/master/documentation/headers-footers.md)
73 | - [Reusable Chunks](https://github.com/PDFTron/web-to-pdf/blob/master/documentation/chunks.md)
74 | - [Lists](https://github.com/PDFTron/web-to-pdf/blob/master/documentation/lists.md)
75 | - [Real time PDF building](https://github.com/PDFTron/web-to-pdf/blob/master/documentation/real-time.md)
76 | - [Styling with CSS & SASS](https://github.com/PDFTron/web-to-pdf/blob/master/documentation/api.md#styles)
77 | - [Assets](https://github.com/PDFTron/web-to-pdf/blob/master/documentation/assets.md)
78 | - [Dynamic content](https://github.com/PDFTron/web-to-pdf/blob/master/documentation/content.md)
79 |
80 | ## Real time PDF Building
81 | With a few changes to your options you can enable real time PDF building!
82 | See [the docs](https://github.com/PDFTron/web-to-pdf/blob/master/documentation/real-time.md) for more info.
83 |
84 | ## Development
85 | ```
86 | git clone https://github.com/PDFTron/web-to-pdf.git
87 | cd web-to-pdf
88 | npm i
89 | ```
90 |
91 | There are examples you can test on in the `examples` folder. These examples are run via scripts in `package.json`
92 |
93 | ## Contributing
94 | Before created a PR, please make sure tests pass:
95 |
96 | `npm run test`
97 |
98 | If you would like to contribute but aren't sure how, please open a ticket saying you would like to contribute.
99 |
100 | Feel free to add tests you feel needed.
101 |
102 | ## Caveats
103 | - Creation of PDF input fields is not supported (not supported by chromium).
104 |
--------------------------------------------------------------------------------
/babel.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | "presets": ["@babel/preset-react"],
3 | "plugins": [
4 | "@babel/plugin-proposal-function-sent",
5 | "@babel/plugin-proposal-export-namespace-from",
6 | "@babel/plugin-proposal-numeric-separator",
7 | "@babel/plugin-proposal-throw-expressions",
8 | "@babel/plugin-proposal-class-properties",
9 | "@babel/plugin-transform-dotall-regex",
10 | "@babel/plugin-proposal-object-rest-spread"
11 | ]
12 | }
--------------------------------------------------------------------------------
/documentation/api.md:
--------------------------------------------------------------------------------
1 | # API
2 |
3 | ## new Renderer(options)
4 |
5 | ```js
6 | const Renderer = require('@pdftron/web-to-pdf');
7 | const renderer = new Renderer(options);
8 | ```
9 | **options**
10 |
11 | - [dirname](#dirname-required) (required)
12 | - [width](#width)
13 | - [height](#height)
14 | - [margin](#margin)
15 | - [keepAlive](#keepAlive)
16 | - [debug](#debug)
17 | - [port](#port)
18 | - [host](#host)
19 | - [autoOpen](#autoopen)
20 | - [args](#args)
21 |
22 | ### dirname (required)
23 | Directory of the file you are working in. Please pass `__dirname` for this option.
24 |
25 | ```js
26 | const renderer = new Renderer({ dirname: __dirname });
27 | ```
28 |
29 | ### width
30 | Width of each page in pixels. Must be an interger
31 |
32 | **default**: 612
33 |
34 | ### height
35 | Height of each page in pixels. Must be an interger value **or** set to 'auto' to match the height of the page.
36 |
37 | **default**: 792
38 |
39 | ### margin
40 | Object specifying page margins. `top`, `bottom`, `left` and `right` are accepted object values. Uses normal CSS values.
41 |
42 | ```js
43 | const Renderer = require('@pdftron/web-to-pdf');
44 | const r = new Renderer({
45 | margin: {
46 | top: '20px',
47 | left: '1in',
48 | right: '20px',
49 | bottom: '20px',
50 | }
51 | })
52 | ```
53 |
54 | ### keepAlive
55 | Set to true to keep the instance in memory when it's done rendering. Useful for using the tool as a service.
56 |
57 | **default**: false
58 |
59 | ### debug
60 | Set to true to enable some debugging logs. Setting this to true will also leave all the source files in your output directory (these are normally deleted after the PDF is generated.)
61 |
62 | **default**: false
63 |
64 | ### port
65 | Port to run the local server on.
66 |
67 | **default**: 8080
68 |
69 | ### host
70 | Host to run the local server on.
71 |
72 | **default**: 127.0.0.1
73 |
74 | ### autoOpen
75 | Set to true to auto open the PDF once its done rendering. Ignored if you are in real time mode.
76 |
77 | **default**: false
78 |
79 | ### args
80 | An array of arguments to pass to the puppeteer `launch` function. Possible values can be found [here](https://peter.sh/experiments/chromium-command-line-switches/)
81 |
82 | ## .render(renderOptions)
83 |
84 | ```js
85 | const Renderer = require('@pdftron/web-to-pdf');
86 | const renderer = new Renderer(options);
87 |
88 | const result = await renderer.render(renderOptions); // see below for renderOptions
89 | ```
90 |
91 | **NOTE** For `realTime` mode, you must pass a path to an options file instead of an options object. See [this](./real-time.md) for more details.
92 |
93 | **NOTE** If you want to render a remote URL, also see [this guide](./remote-api.md)
94 |
95 | #### Returns:
96 |
97 | Returns a promise that resolves with the following object:
98 |
99 | ```
100 | {
101 | sourceMap: {
102 | ...list of read/writes that were made. Used mostly for debugging.
103 | },
104 | output: 'path to where the PDF was written, relative to CWD',
105 | metadata: {
106 | numberOfPages: 'how many pages the PDF is'
107 | }
108 | }
109 | ```
110 |
111 |
112 | **Render options:**
113 | - [templateSource](#templatesource-required) (required)
114 | - [react component](#react-component)
115 | - [html string](#html-string)
116 | - [html file](#html-file)
117 | - [function](#function)
118 | - [url](#url)
119 | - [contentSource](#contentsource)
120 | - [pageClass](#pageClass)
121 | - [chunks](#chunks)
122 | - [outputFolder](#outputfolder)
123 | - [outputName](#outputname)
124 | - [styles](#styles)
125 | - [ignoreWatch](#ignorewatch)
126 | - [middleware](#middleware)
127 |
128 |
129 | ### templateSource (required)
130 | The source for your PDF structure. Can be one of the following:
131 |
132 | #### react component
133 | If you pass a React component, it will be rendered to HTML via React.renderToString(). **Keep in mind that this is a server render**, so you dont have access to browser APIs, and you won't get all the lifecycle functions.
134 |
135 |
136 | ```js
137 | class Component extends React.Component {
138 | render() {
139 | return (
140 |
141 |
My content here!
142 |
143 | )
144 | }
145 | }
146 |
147 | const renderer = new Renderer({ dirname: __dirname });
148 | renderer.render({
149 | templateSource: Component
150 | });
151 | ```
152 |
153 | #### html (string)
154 | If you pass a valid html string, it will be used directly to render the PDF.
155 |
156 | ```js
157 | const renderer = new Renderer({ dirname: __dirname });
158 | renderer.render({
159 | templateSource: `
160 |
161 |
162 |
163 | My content goes here!
164 |
165 |
166 |
167 | `
168 | });
169 | ```
170 |
171 | #### html (file)
172 | If you pass a path to a html file, it will be used directly to render the PDF.
173 |
174 | ```js
175 | const renderer = new Renderer({ dirname: __dirname });
176 | renderer.render({
177 | templateSource: 'index.html'
178 | });
179 | ```
180 |
181 | #### function
182 | If you pass a function, it will be called and the result will be used to render the PDF. This means the function should return valid HTML, **or a promise that resolves with valid HTML**.
183 |
184 | The function is passed the content that is passed via the [contentSource](#contentSource) option. This makes dynamic HTML structures possible.
185 |
186 | ```js
187 | const renderer = new Renderer({ dirname: __dirname });
188 | renderer.render({
189 | templateSource: (content) => {
190 | return `
191 |
192 |
193 |
200 |
201 |
202 | `
203 | }
204 | });
205 | ```
206 |
207 | #### url
208 | If you pass a URL, the remote page will be rendered.
209 |
210 | Url must start with `http` or `https`.
211 |
212 | Also see [this guide](./remote-api.md)
213 |
214 | ```js
215 | const renderer = new Renderer({ dirname: __dirname });
216 | renderer.render({
217 | templateSource: 'https://google.com'
218 | });
219 | ```
220 |
221 | ### contentSource
222 | Either a JS object or a path to a JSON file containing your content. This content will be used to replace your [mustaches](content.md), and is also passed into the [templateSource function method.](#function). The content is also available at `window.content` if you are using some client side rendering. If not supplied, no content will be replaced.
223 |
224 | **NOTE:** content replacement will only work if you pass in raw HTML, or pass a [react component](#react-component) to templateSource. If you are using Javascript to generate the DOM on the client, content replacement will not work. In this case you can access your data at `window.content`.
225 |
226 | default: `null`
227 |
228 | #### json (file)
229 |
230 | ```js
231 |
232 | const html = `
233 |
234 |
235 |
260 |
261 |
262 | `
263 |
264 | renderer.render({
265 | templateSource: html,
266 | contentSource: {
267 | "myString": "Hello world!"
268 | }
269 | });
270 | ```
271 |
272 |
273 | ### pageClass
274 | Use your own custom class to seperate pages.
275 |
276 | By default, each div with a `Page` class will be its own page. You can change this by setting this property.
277 |
278 | ```js
279 | const html = `
280 |
281 |
282 |
288 |
289 |
290 | `
291 |
292 | renderer.render({
293 | templateSource: html,
294 | pageClass: 'CustomPage'
295 | });
296 | ```
297 |
298 |
299 | ### chunks
300 | A map of HTML snippets to reuse throughout your template.
301 |
302 | Accepts any of the types that [templateSource](#templatesource) accepts (except a remote url). Whatever is passed will replace any {{chunkName}} mustaches.
303 |
304 | See [here](./content.md) for more info on mustache syntax.
305 | See [here](./chunks.md) for more info and examples on chunks.
306 |
307 | ```js
308 | const renderer = new Renderer({ dirname: __dirname });
309 |
310 | const html = `
311 |
312 |
313 |
333 | `
334 |
335 | renderer.render({
336 | templateSource: html,
337 | contentSource: {
338 | "myString": "Hello world!"
339 | },
340 | chunks: {
341 | header: header,
342 | copy: mainCopy
343 | }
344 | });
345 | ```
346 |
347 | ### outputFolder
348 | A string containing the name of the desired output folder. Will be created relative to the CWD.
349 |
350 | default: `outputs`
351 |
352 | ```js
353 | const renderer = new Renderer({ dirname: __dirname });
354 | renderer.render({
355 | templateSource: 'template.html',
356 | outputFolder: 'pdf-outputs'
357 | });
358 | ```
359 |
360 | Will create `./pdf-outputs/index.pdf`
361 |
362 | ### outputName
363 | Name of the PDF file that is generated.
364 |
365 | default `index`
366 |
367 | ```js
368 | const renderer = new Renderer({ dirname: __dirname });
369 | renderer.render({
370 | templateSource: 'template.html',
371 | outputFolder: 'pdf-outputs',
372 | outputName: 'report-card'
373 | });
374 | ```
375 |
376 | Will create `./pdf-outputs/report-card.pdf`
377 |
378 | ### styles
379 |
380 | **IMPORTANT: If your css/scss is referenced (via link tags) in your html, then you don't need to do this. [See the examples to learn more](../examples)**
381 |
382 | An array of string representing paths to css files or actual css or scss you want to use to style your PDF. If you provide a `.scss` file, it (and any linked files) will be automatically compiled to css. These styles will be automatically injected into the HTML generated by your [templateSource](#templateSource). **This is only useful if you cant link the css in your HTML for some reason.**
383 |
384 |
385 | default: `[]`
386 |
387 | ```js
388 | const renderer = new Renderer({ dirname: __dirname });
389 | renderer.render({
390 | templateSource: 'template.html',
391 | styles: [
392 | 'style.css', // paths to css
393 | 'customStyle.scss', // paths to scss
394 | `
395 | #test {
396 | color: red /
397 | }
398 | ` // or actual css or scss
399 | ],
400 | });
401 | ```
402 |
403 | ### ignoreWatch
404 | Sometimes you will have your own file watcher and you won't have to reply on our on change function for certain files.
405 |
406 | Accepts an [anymatch](https://www.npmjs.com/package/anymatch) array or glob of files to ignore.
407 |
408 | default: null
409 |
410 | ```js
411 | const renderer = new Renderer({ dirname: __dirname });
412 | renderer.render({
413 | templateSource: 'template.html',
414 | ignoreWatch: "**/bundle.js" // ignore bundle.js
415 | });
416 | ```
417 |
418 | ### middleware
419 | An array of functions used to transform HTML. Each function will be called one after the other. Each function recieves HTML as a parameter and should return the transformed HTML string.
420 |
421 | Middleware functions can be asyncronous. The next middleware in the chain won't get called until the previous one is finished
422 |
423 | ```js
424 | const renderer = new Renderer({ dirname: __dirname });
425 | renderer.render({
426 | templateSource: 'template.html',
427 | middleware: [
428 | (html) => {
429 | html = html.replace(/p/g, "h5");
430 | return html;
431 | }
432 | ]
433 | });
434 | ```
435 |
436 | ## .on(key, callback)
437 | Subscribe to event throughout the render process. Possible keys are
438 |
439 | `change` - called when a file used to render changes, useful for [real time pdf building](./real-time.md).
440 |
441 |
442 | `html` - called when the final HTML is determined (useful for debugging). Callback is passed an html string. Not called when using a remote URL.
443 |
444 | ## .stop()
445 | Closes down all services.
446 |
447 |
448 |
449 |
--------------------------------------------------------------------------------
/documentation/assets.md:
--------------------------------------------------------------------------------
1 | # Assets
2 |
3 | Assets referenced in your html will be automatically served and watched (if in real time mode). Please reference them relatively to your html file:
4 |
5 | File system
6 | ```
7 | myProject/
8 | - index.html
9 | assets/
10 | - image.png
11 | ```
12 |
13 | HTML
14 | ```html
15 |
16 |
17 |
18 | ```
19 |
--------------------------------------------------------------------------------
/documentation/chunks.md:
--------------------------------------------------------------------------------
1 | # Chunks
2 |
3 | Chunks are reusable snippets of HTML. They are referenced with mustache syntax, the same as [dynamic content](./content.md);
4 |
5 | These are useful for any reusuable chunks of code.
6 |
7 | Chunks can be any format that [templateSource](./api.md#templatesource-required) can be (html string, html file, react component, function, etc)
8 |
9 | To set the chunk content, use the [chunks](./api.md#chunks) render options.
10 |
11 | Chunks can be used to automatially append html to the top and bottom of every page - aka **headers and footers**. See [this guide](./headers-footers.md) for details
12 |
13 | ## Example
14 |
15 | ```js
16 | const renderer = new Renderer({ dirname: __dirname });
17 |
18 | // main template
19 | const templateSource = `
20 |
21 | {{chunkOne}}
22 | My page 1 content here
23 |
24 |
25 |
26 | {{chunkTwo}}
27 | My page 2 content here
28 |
29 |
30 |
31 | {{chunkOne}}
32 | My page 3 content here
33 | {{chunkTwo}}
34 |
85 | ```
86 |
87 |
--------------------------------------------------------------------------------
/documentation/content.md:
--------------------------------------------------------------------------------
1 | # Dynamic Content
2 |
3 | We use mustache syntax to do content replacements. You may use mustache syntax in any html [templateSource](api.md#templateSource). The replacement happens AFTER the html is generated on the server.
4 |
5 | Your content can be loaded by the [contentSource](api.md#contentSource) option.
6 |
7 | If you are using client side JS (like React) to generate your DOM, mustaches will not be replaced. In this case, the content will be available at `window.content` for you to use dynamically.
8 |
9 | Content can be nested (see examples below)
10 |
11 | ## Examples:
12 |
13 | - [In HTML](#in-html-file)
14 | - [In templateSource function](#in-templatesource-function)
15 | - [In react component](#in-react-component)
16 |
17 | ## In HTML file
18 |
19 | index.js
20 | ```js
21 | const renderer = new Renderer({ dirname: __dirname });
22 | renderer.render({
23 | contentSource: 'content.json',
24 | templateSource: 'index.html',
25 | });
26 | ```
27 |
28 | index.html
29 | ```html
30 |
31 |
32 |
106 |
107 |
108 | ```
109 |
110 | ## In react component (server side)
111 | Content is passed as a prop to the React component, but you can even use the mustache in your react component if you want.
112 |
113 | index.js
114 | ```js
115 | class Comp extends React.Component {
116 | render() {
117 | const { content } = this.props;
118 | return (
119 |
149 |
150 |
151 | ```
152 |
153 |
--------------------------------------------------------------------------------
/documentation/creating-pages.md:
--------------------------------------------------------------------------------
1 | # Creating Pages
2 | Creating pages is easy! All you need to do is apply the class `.Page` to a wrapper div. From this point, anything in that container will be part of the page.
3 |
4 | You can also use your own identifier to split pages. Pass in your custom value to the [pageClass](./api.md#pageClass) and it will be used to split pages.
5 |
6 | To create multiple pages, simply include mulitple page divs.
7 |
8 | **If you do not include a page div, all your content will be wrapped in a page.**
9 |
10 | [Click here](./api.md) for the full Renderer API
11 |
12 | ## Page numbers
13 | Page numbers can be inserted by using `{{pageNumber}}` The mustache will be automatially replaced with the proper page number.
14 |
15 | ## Examples
16 |
17 | ### HTML
18 |
19 | ```js
20 |
21 | const html = `
22 |
23 |
24 |
25 | page {{pageNumber}}
26 |
27 |
28 |
29 | page {{pageNumber}}
30 |
31 |
32 |
33 | page {{pageNumber}}
34 |
35 |
36 |
37 | `
38 |
39 | const renderer = new Renderer({ dirname: __dirname });
40 | renderer.render({
41 | templateSource: html,
42 | });
43 |
44 | // NOTE: You do not have to include the or tags if you have no header items. So this would be okay as well:
45 | /*
46 | const html = `
47 |
68 | ```
--------------------------------------------------------------------------------
/documentation/lists.md:
--------------------------------------------------------------------------------
1 | # Lists
2 |
3 | When rendering lists of data, its possible that the contents of the list will overflow off the page. We solve this problem by dynamically altering your lists to fit to individual pages.
4 |
5 | To use this feature, simply wrap your list contents in a `.List` class. We will take any overflow content and insert it into a new page!
6 |
7 | ```js
8 |
9 |
10 | {
11 | myItems.map(item => {
12 | return
{item}
13 | })
14 | }
15 |
16 |
17 |
18 | ```
--------------------------------------------------------------------------------
/documentation/real-time.md:
--------------------------------------------------------------------------------
1 | # Real time PDF Building
2 |
3 | Real time mode allows you to view your PDF in the browser as you build it! Any change to a file will rebuild the PDF and hot reload it in the browser.
4 |
5 | **To enable real time mode, please follow these two (three if you're using react) steps:**
6 |
7 | ## 1) Export renderOptions from a different file.
8 | In order for us to get your new render params when they change, we need to be able to dynamically require them. In order to do this, your render params must be exported from another file, and you must pass us a path to this file. This file must export (default) a function that returns your params. This function may be asyncronous if you need to do some network fetching here.
9 |
10 | See [here](./api.md#renderrenderoptions) for possible renderOptions
11 |
12 | Example of real time building [here](./../examples/real-time)
13 |
14 | **index.js**
15 | ```js
16 | const renderer = new Renderer({ dirname: __dirname });
17 |
18 | const render = () => {
19 | renderer.render('options.js');
20 | }
21 |
22 | renderer.on('change', render);
23 | render();
24 | ```
25 |
26 | **options.js**
27 | ```js
28 |
29 | module.exports = () => {
30 | return {
31 | templateSource: "
Hey!!!
",
32 | // ...other renderOptions
33 | }
34 | }
35 |
36 | ```
37 |
38 | ## 2) Add a change listener
39 |
40 | To trigger re-renders, you need to hook into the `onchange` event. Follow this pattern to do so:
41 |
42 | ```js
43 | const renderer = new Renderer({ dirname: __dirname });
44 |
45 | const render = () => {
46 | renderer.render('options.js');
47 | }
48 |
49 | renderer.on('change', render);
50 | render();
51 | ```
52 |
53 | Web-to-pdf will trigger your render function any time a file changes.
54 |
55 | ## 3) React components (server rendered)
56 |
57 | If you are using a React component as a source and you want hot reloading, you need to use our special `pathTo` function to require it.
58 |
59 | In the function exported from your [options file](#1-export-renderoptions-from-a-different-file), use the first parameter to reference your react component.
60 |
61 | Example:
62 |
63 | **options.js**
64 | ```js
65 | module.exports = async (pathTo) => {
66 |
67 | return {
68 | templateSource: pathTo('./root'), // ./root exports the root react component
69 | }
70 |
71 | }
72 | ```
73 |
74 | [Here is an example](../examples/complex-2) of this method in use.
75 |
76 |
--------------------------------------------------------------------------------
/documentation/remote-api.md:
--------------------------------------------------------------------------------
1 | # Remote API
2 |
3 | Passing a URL to templateSource allows you to render a remote page. The API is the same as rendering a local PDF, but here are some ways you can edit the remote PDF.
4 |
5 | ## new Renderer(options)
6 | See [renderer api](./api.md#new-rendereroptions) for constructor options
7 |
8 | ```js
9 | const Renderer = require('@pdftron/web-to-pdf');
10 | const renderer = new Renderer(options);
11 | ```
12 |
13 | ## .render(renderOptions)
14 | - [templateSource](#templateSource) (required)
15 | - [styles](#styles),
16 | - [scripts](#scripts),
17 | - [outputFolder](#outputfolder)
18 | - [outputName](#outputname)
19 | - [ignoreWatch](#ignorewatch)
20 |
21 | **NOTE** For `realTime` mode, you must pass a path to an options file instead of an options object. See [this](./real-time.md) for more details.
22 |
23 | **NOTE** If you want to render a local html file, please see [this guide](./api.md)
24 |
25 | ### templateSource
26 | The URL of the page to render.
27 |
28 | ```js
29 | const renderer = new Renderer(options);
30 |
31 | renderer.renderRemote({
32 | templateSource: 'http://google.com'
33 | });
34 | ```
35 |
36 | ### styles
37 | An array of paths to `css` or `scss` files to inject into the page. Useful for removing unwanted elements from the page.
38 |
39 | Paths are relative to the current file.
40 |
41 | ```js
42 | const renderer = new Renderer(options);
43 |
44 | renderer.renderRemote({
45 | templateSource: 'http://google.com',
46 | styles: [
47 | 'style.css',
48 | 'style.scss',
49 | ]
50 | });
51 | ```
52 |
53 | ### scripts
54 | An array of paths to javscript files to inject into the page. Useful for running custom scripts before the PDF is generated.
55 |
56 | Scripts are injected into the top of the page.
57 |
58 | Paths are relative to the current file.
59 |
60 | ```js
61 | const renderer = new Renderer(options);
62 |
63 | renderer.renderRemote({
64 | templateSource: 'http://google.com',
65 | scripts: [
66 | 'myScript.js',
67 | ]
68 | });
69 | ```
70 |
71 | ### outputFolder
72 | A string containing the name of the desired output folder. Will be created relative to the CWD.
73 |
74 | default: `outputs`
75 |
76 | ```js
77 | const renderer = new Renderer({ dirname: __dirname });
78 | renderer.renderRemote({
79 | templateSource: 'http://google.com',
80 | outputFolder: 'pdf-outputs'
81 | });
82 | ```
83 |
84 | Will create `./pdf-outputs/index.pdf`
85 |
86 | ### outputName
87 | Name of the PDF file that is generated.
88 |
89 | default `index`
90 |
91 | ```js
92 | const renderer = new Renderer({ dirname: __dirname });
93 | renderer.renderRemote({
94 | templateSource: 'http://google.com',
95 | outputFolder: 'pdf-outputs',
96 | outputName: 'report-card'
97 | });
98 | ```
99 |
100 | Will create `./pdf-outputs/report-card.pdf`
101 |
102 | ### ignoreWatch
103 | Sometimes you will have your own file watcher and you won't have to reply on our on change function for certain files.
104 |
105 | Accepts an [anymatch](https://www.npmjs.com/package/anymatch) array or glob of files to ignore.
106 |
107 | default: null
108 |
109 | ```js
110 | const renderer = new Renderer({ dirname: __dirname });
111 | renderer.renderRemote({
112 | templateSource: 'http://google.com',
113 | ignoreWatch: "**/style.scss" // ignore style.scss
114 | });
115 | ```
116 |
117 |
118 |
119 |
--------------------------------------------------------------------------------
/examples/README.md:
--------------------------------------------------------------------------------
1 | # Examples
2 | This directory contains a bunch of examples.
3 |
4 | Here is a categorized list of examples:
5 |
6 | ### The basics
7 | - [HTML to PDF](./html-to-pdf-basic)
8 | - [React to PDF](./react-to-pdf)
9 | - [Function to PDF](./function-to-pdf)
10 | - [Local files to PDF](./files-as-source)
11 |
12 | ### Content
13 | - [Dynamic content/copy](./dynamic-content)
14 | - [Reusuable HTML chunks](./chunks)
15 | - [Page numbers](./page-numbers)
16 |
17 | ### Structure
18 | - [Headers and footers](./headers-footers)
19 |
20 | ### Real Time
21 | - [Real time PDF building](./real-time)
22 |
23 | ### Cool stuff
24 | - 💥[**Using third party JS libraries to render stuff**](./javascript)💥
25 | - 💥[**Running as a service**](./as-a-service)💥
--------------------------------------------------------------------------------
/examples/as-a-service/client.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
23 |
24 |
--------------------------------------------------------------------------------
/examples/as-a-service/readme.md:
--------------------------------------------------------------------------------
1 | # As a service.
2 |
3 | You can use web-to-pdf as an online service to render PDFs!
4 |
5 | This example uses a node + express server to provide a PDF rendering API.
6 |
7 | When the client presses the submit button, it sends a request to the API that tells it to render whatever remote page the user enters. When its done rendering, it returns the remote location of the generated PDF, and the client navigates there.
8 |
9 | **This is a very basic example - more precautions should be taken in a real life scenerio**.
10 |
11 | ### Running
12 |
13 | If you dont have the repo installed, do so by running:
14 | ```
15 | git clone https://github.com/PDFTron/web-to-pdf.git
16 | cd web-to-pdf
17 | npm i
18 | ```
19 |
20 | Run the example:
21 | ```
22 | npx babel-node examples/as-a-service/server.js
23 | ```
24 |
25 | ### Try the sample:
26 | Navigate to http://localhost:8080 and enter a website to render as a PDF. A new tab will open displaying the PDF.
--------------------------------------------------------------------------------
/examples/as-a-service/server.js:
--------------------------------------------------------------------------------
1 | const Renderer = require('../../src');
2 | const express = require('express');
3 | const app = express();
4 | const Path = require('path');
5 | const port = 8080;
6 |
7 | const r = new Renderer({ dirname: __dirname, keepAlive: true, height: 'auto' });
8 |
9 | // use express to serve static assets at /outputs
10 | app.use('/outputs', express.static(Path.resolve(__dirname, './outputs')));
11 |
12 | // serve the client app
13 | app.get('/', (req, res) => {
14 | res.sendFile(Path.join(__dirname + '/client.html'));
15 | })
16 |
17 | // convert api
18 | app.get('/convert', async (req, res) => {
19 | const path = req.query.url;
20 | const u = new URL(path);
21 |
22 | await r.render({
23 | templateSource: path,
24 | outputFolder: Path.resolve(__dirname, './outputs'), // render stuff (relative to this file)
25 | outputName: u.hostname
26 | });
27 |
28 | // returns the remote location of the file
29 | res.send(`http://localhost:${port}/outputs/${u.hostname}.pdf`);
30 | });
31 |
32 | app.listen(port, () => { console.log(`Listening on port ${port}. Navigate to http://localhost:8080 to test the app!`) });
33 |
--------------------------------------------------------------------------------
/examples/assets/README.md:
--------------------------------------------------------------------------------
1 | # NAME
2 | DESCRIPTION
3 |
4 | ### Running
5 |
6 | If you dont have the repo installed, do so by running:
7 | ```
8 | git clone https://github.com/XodoDocs/web-to-pdf.git
9 | cd web-to-pdf
10 | npm i
11 | ```
12 |
13 | Run the example:
14 | ```
15 | npx babel-node examples/assets/index.js
16 | ```
17 |
18 | ### APIs and Techniques Used
19 | - [HTML String as template source](../../documentation/api.md#html-string)
20 | - [Output name](../../documentation/api.md#outputname)
--------------------------------------------------------------------------------
/examples/assets/img/pdftron.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ApryseSDK/web-to-pdf/651ebc4ee85e53b7bb161f6b0443d9b08c9be283/examples/assets/img/pdftron.png
--------------------------------------------------------------------------------
/examples/assets/img/pdftron2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ApryseSDK/web-to-pdf/651ebc4ee85e53b7bb161f6b0443d9b08c9be283/examples/assets/img/pdftron2.png
--------------------------------------------------------------------------------
/examples/assets/index.js:
--------------------------------------------------------------------------------
1 | const WebToPDF = require('../../src/index');
2 | // const WebToPDF = require('@pdftron/web-to-pdf'); // or this
3 |
4 | (async () => {
5 | const renderer = new WebToPDF({ dirname: __dirname, debug: true });
6 |
7 | const html = `
8 |
9 |
10 |
Web to PDF
11 |
Basic assets example
12 |
13 |
14 |
15 | This should have a background image
16 |
17 |
18 |
19 | `;
20 |
21 | const style = `
22 | .bg {
23 | background-image: url('./img/pdftron2.png');
24 | }
25 | `
26 |
27 | renderer.render({
28 | templateSource: html,
29 | styles: [style],
30 | outputName: 'assetsBasic'
31 | })
32 |
33 | })()
34 |
--------------------------------------------------------------------------------
/examples/chunks/README.md:
--------------------------------------------------------------------------------
1 | # Chunks example
2 | This example shows how to use the chunks api to insert chunks of html throughout your template.
3 |
4 | ### Running
5 |
6 | If you dont have the repo installed, do so by running:
7 | ```
8 | git clone https://github.com/PDFTron/web-to-pdf.git
9 | cd web-to-pdf
10 | npm i
11 | ```
12 |
13 | Run the example:
14 | ```
15 | npx babel-node examples/chunks
16 | ```
17 |
18 | ### APIs and Techniques Used
19 | - [Chunks](../../documentation/chunks.md)
20 | - [HTML String as template source](../../documentation/api.md#html-string)
21 | - [HTML File as chunk source](../../documentation/api.md#html-file)
22 | - [React component as chunk source](../../documentation/api.md#react-component)
23 | - [Output name](../../documentation/api.md#outputname)
--------------------------------------------------------------------------------
/examples/chunks/index.js:
--------------------------------------------------------------------------------
1 | const WebToPDF = require('../../src/index');
2 | // const WebToPDF = require('@pdftron/web-to-pdf'); // or this
3 |
4 | const React = require('react');
5 |
6 | class ReactChunk extends React.Component {
7 | render() {
8 | return (
9 |
--------------------------------------------------------------------------------
/examples/dynamic-content/README.md:
--------------------------------------------------------------------------------
1 | # Dynamic Content Example
2 | This is an example of using dynamic content in your PDFs.
3 |
4 | This is useful for writing a script to generate a PDF invoice, report, report card, etc. You can use your own service to fetch the content and dynamically insert it into your template.
5 |
6 | ### Running
7 |
8 | If you dont have the repo installed, do so by running:
9 | ```
10 | git clone https://github.com/PDFTron/web-to-pdf.git
11 | cd web-to-pdf
12 | npm i
13 | ```
14 |
15 | Run the example:
16 | ```
17 | npx babel-node examples/dynamic-content
18 | ```
19 |
20 | ### APIs and Techniques Used
21 | - [HTML File as template source](../../documentation/api.md#html-file)
22 | - [Dynamic content](../../documentation/content.md)
23 | - [Output name](../../documentation/api.md#outputname)
--------------------------------------------------------------------------------
/examples/dynamic-content/index.js:
--------------------------------------------------------------------------------
1 | const WebToPDF = require('../../src/index');
2 | // const WebToPDF = require('@pdftron/web-to-pdf'); // or this
3 |
4 | (async () => {
5 | const renderer = new WebToPDF({ dirname: __dirname });
6 |
7 | // You could load this JSON object from your own service
8 | // This is useful for generating reports, invoices, etc
9 | const myContent = {
10 | pageTitle: "Using dynamic content in your PDFs",
11 | subtitle: "This example shows how you can use JSON data to render dynamic content in your PDF",
12 | content: {
13 | body: "You can even use nested data!"
14 | }
15 | }
16 |
17 | await renderer.render({
18 | templateSource: './src/index.html',
19 | contentSource: myContent,
20 | outputName: "dynamic-content"
21 | })
22 |
23 | })()
24 |
--------------------------------------------------------------------------------
/examples/dynamic-content/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
{{pageTitle}}
7 |
{{subtitle}}
8 |
{{content.body}}
9 |
10 |
--------------------------------------------------------------------------------
/examples/dynamic-content/src/style.scss:
--------------------------------------------------------------------------------
1 | .Page {
2 | display: flex;
3 | flex-direction: column;
4 | height: 100%;
5 | justify-content: center;
6 | align-items: center;
7 | }
--------------------------------------------------------------------------------
/examples/files-as-source/README.md:
--------------------------------------------------------------------------------
1 | # Local files as a source
2 | This example shows how you can use `html`, `scss` and `css` files as sources.
3 |
4 | This example also shows how you can use Google Fonts to style your text.
5 |
6 | ### Running
7 |
8 | If you dont have the repo installed, do so by running:
9 | ```
10 | git clone https://github.com/PDFTron/web-to-pdf.git
11 | cd web-to-pdf
12 | npm i
13 | ```
14 |
15 | Run the example:
16 | ```
17 | npx babel-node examples/files-as-source/index.js
18 | ```
19 |
20 | ### APIs and Techniques Used
21 | - [HTML File as template source](../../documentation/api.md#html-file)
22 | - [Output name](../../documentation/api.md#outputname)
--------------------------------------------------------------------------------
/examples/files-as-source/index.js:
--------------------------------------------------------------------------------
1 | const WebToPDF = require('../../src/index');
2 | // const WebToPDF = require('@pdftron/web-to-pdf'); // or this
3 |
4 | (async () => {
5 | const renderer = new WebToPDF({ dirname: __dirname });
6 |
7 | await renderer.render({
8 | templateSource: './src/index.html',
9 | outputName: 'files-as-source'
10 | })
11 | })()
12 |
--------------------------------------------------------------------------------
/examples/files-as-source/src/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
Using an HTML file as a source.
9 |
You can use an HTML file to generate a PDF. You can even reference external CSS/SCSS as seen above!
10 |
This example uses Google fonts (imported in index.scss, check it out!)
11 |
12 |
13 |
--------------------------------------------------------------------------------
/examples/files-as-source/src/index.scss:
--------------------------------------------------------------------------------
1 | // You can use external web fonts!
2 | @import url('https://fonts.googleapis.com/css?family=Roboto');
3 |
4 | .Page {
5 | h1, p {
6 | font-family: Roboto;
7 | }
8 |
9 | display: flex;
10 | flex-direction: column;
11 | justify-content: center;
12 | align-items: center;
13 | }
14 |
--------------------------------------------------------------------------------
/examples/function-to-pdf/README.md:
--------------------------------------------------------------------------------
1 | # Function to PDF example
2 | Web-to-pdf can accept a function as a source. This function can be async, meaning you can fetch data to use when rendering your PDF.
3 |
4 | ### Running
5 |
6 | If you dont have the repo installed, do so by running:
7 | ```
8 | git clone https://github.com/PDFTron/web-to-pdf.git
9 | cd web-to-pdf
10 | npm i
11 | ```
12 |
13 | Run the example:
14 | ```
15 | npx babel-node examples/function-to-pdf/index.js
16 | ```
17 |
18 | ### APIs and Techniques Used
19 | - [Function as template source](../../documentation/api.md#function)
20 | - [SCSS Strings as styles](../../documentation/api.md#styles)
21 | - [Output name](../../documentation/api.md#outputname)
--------------------------------------------------------------------------------
/examples/function-to-pdf/index.js:
--------------------------------------------------------------------------------
1 | const WebToPDF = require('../../src/index');
2 | // const WebToPDF = require('@pdftron/web-to-pdf'); // or this
3 |
4 | const fetch = require('node-fetch');
5 |
6 | (async () => {
7 | const renderer = new WebToPDF({ dirname: __dirname });
8 |
9 | const getHTML = async () => {
10 | const response = await fetch('https://jsonplaceholder.typicode.com/todos');
11 | let json = await response.json();
12 |
13 | json = json.slice(0, 10);
14 |
15 | const content = json.reduce((acc, data) => {
16 | return acc + `
17 |