Skip to content

Commit 839e8c6

Browse files
author
Andrey
committed
Added HTML conversion
1 parent 662a63f commit 839e8c6

File tree

12 files changed

+45
-34
lines changed

12 files changed

+45
-34
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ The endpoint converts the file to a PDF. Conversion is possible for the followin
5454
##### HTTP Request
5555
`GET http://localhost:9000/convert/:filename`
5656

57+
### Convert to PDF from HTML
58+
59+
The endpoint converts the HTML to a PDF. There are several settings available to get the best results. Uses [PDFTron Node.js API for HTML2PDF](https://www.pdftron.com/documentation/samples/node/js/HTML2PDFTest?platforms=nodejs).
60+
61+
##### HTTP Request
62+
`GET http://localhost:9000/convertHTML/:filename-:pathToHTML`
63+
64+
##### Example
65+
Converts an HTML form to a PDF
66+
`http://localhost:9000/convertHTML/myhtml-index.html`
67+
5768
### Optimize PDF
5869

5970
The endpoint converts the PDF to an optimized PDF to be used with [PDFTron WebViewer](https://www.pdftron.com/webviewer/demo/). Uses [PDFTron Node.js API](https://www.pdftron.com/api/pdfnet-node/PDFNet.PDFDoc.html#saveViewerOptimized__anchor).

app.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
const express = require('express');
22
const fs = require('fs');
33
const path = require('path');
4+
45
const { PDFNet } = require('@pdftron/pdfnet-node');
56
const mimeType = require('./modules/mimeType');
7+
68
const filesPath = './files';
79

810
const app = express();
@@ -127,12 +129,11 @@ app.get('/convertHTML/:filename-:htmlPath', (req, res) => {
127129
const main = async () => {
128130
try {
129131
await PDFNet.HTML2PDF.setModulePath(
130-
path.resolve(__dirname, './pdfnet-node/lib/'),
132+
path.resolve(__dirname, './node_modules/@pdftron/pdfnet-node/lib/'),
131133
);
132134
const settings = await PDFNet.HTML2PDF.WebPageSettings.create();
133135
settings.setAllowJavaScript(true);
134136
settings.setProduceForms(true);
135-
settings.SetPrintBackground(false);
136137
const html2pdf = await PDFNet.HTML2PDF.create();
137138
const pdfdoc = await PDFNet.PDFDoc.create();
138139
await html2pdf.insertFromUrl2(inputPath, settings);

files/document.docx.pdf

932 Bytes
Binary file not shown.

files/myhtml.pdf

-20 Bytes
Binary file not shown.

files/new.pdf

60 Bytes
Binary file not shown.

files/optimized_webviewer.pdf

0 Bytes
Binary file not shown.
152 Bytes
Binary file not shown.
8 Bytes
Binary file not shown.

package-lock.json

Lines changed: 18 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
"main": "index.js",
66
"scripts": {
77
"start": "nodemon server.js",
8-
"postinstall": "node tools/copy-pdfnet-lib.js",
98
"test": "mocha --timeout 10000"
109
},
1110
"author": "",
1211
"license": "ISC",
1312
"dependencies": {
14-
"@pdftron/pdfnet-node": "^7.1.1-1",
13+
"@pdftron/pdfnet-node": "^8.0",
1514
"dotenv": "^8.2.0",
1615
"express": "^4.17.1",
1716
"nodemon": "^2.0.3"

0 commit comments

Comments
 (0)