@pdftron/pdfnet-node-samples 10.1.0 → 10.1.1-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pdftron/pdfnet-node-samples",
3
- "version": "10.1.0",
3
+ "version": "10.1.1-beta",
4
4
  "description": "Sample code for the @pdftron/pdfnet-node package.",
5
5
  "scripts": {
6
6
  "test": "run-script-os",
@@ -12,7 +12,7 @@
12
12
  "license": "Commercial",
13
13
  "homepage": "https://www.pdftron.com",
14
14
  "dependencies": {
15
- "@pdftron/pdfnet-node": "~10.1.0",
15
+ "@pdftron/pdfnet-node": "~10.1.1-beta",
16
16
  "run-script-os": "^1.1.6"
17
17
  }
18
18
  }
@@ -29,10 +29,11 @@ const PDFTronLicense = require('../LicenseKey/LicenseKey');
29
29
  exports.runHTML2PDFTest = () => {
30
30
  const main = async () => {
31
31
  const outputPath = '../TestFiles/Output/html2pdf_example';
32
- const host = 'https://www.pdftron.com';
32
+ const host = 'https://docs.apryse.com';
33
33
  const page0 = '/';
34
- const page1 = '/support';
35
- const page2 = '/blog';
34
+ const page1 = '/all-products/';
35
+ const page2 = '/documentation/web/faq';
36
+
36
37
  // For HTML2PDF we need to locate the html2pdf module. If placed with the
37
38
  // PDFNet library, or in the current working directory, it will be loaded
38
39
  // automatically. Otherwise, it must be set manually using HTML2PDF.setModulePath.
@@ -58,11 +59,8 @@ const PDFTronLicense = require('../LicenseKey/LicenseKey');
58
59
 
59
60
  html2pdf.insertFromUrl(host.concat(page0));
60
61
  // now convert a web page, sending generated PDF pages to doc
61
- if (await html2pdf.convert(doc)) {
62
- doc.save(outputPath.concat('_01.pdf'), PDFNet.SDFDoc.SaveOptions.e_linearized);
63
- } else {
64
- console.log('Conversion failed.');
65
- }
62
+ await html2pdf.convert(doc);
63
+ doc.save(outputPath.concat('_01.pdf'), PDFNet.SDFDoc.SaveOptions.e_linearized);
66
64
  } catch (err) {
67
65
  console.log(err);
68
66
  }
@@ -84,12 +82,8 @@ const PDFTronLicense = require('../LicenseKey/LicenseKey');
84
82
  html2pdf.insertFromUrl(host.concat(page0));
85
83
 
86
84
  // convert the web page, appending generated PDF pages to doc
87
- if (await html2pdf.convert(doc)) {
88
- doc.save(outputPath.concat('_02.pdf'), PDFNet.SDFDoc.SaveOptions.e_linearized);
89
- } else {
90
- console.log('Conversion failed. HTTP Code: ' + await html2pdf.getHttpErrorCode());
91
- console.log(await html2pdf.getLog());
92
- }
85
+ await html2pdf.convert(doc);
86
+ doc.save(outputPath.concat('_02.pdf'), PDFNet.SDFDoc.SaveOptions.e_linearized);
93
87
  } catch (err) {
94
88
  console.log(err);
95
89
  }
@@ -111,11 +105,11 @@ const PDFTronLicense = require('../LicenseKey/LicenseKey');
111
105
  const settings = await PDFNet.HTML2PDF.WebPageSettings.create();
112
106
  await settings.setZoom(0.5);
113
107
  converter.insertFromUrl2(host.concat(page0), settings);
114
- const is_conversion_0_successful = await converter.convert(doc);
108
+ await converter.convert(doc);
115
109
 
116
110
  // convert page 1 with the same settings, appending generated PDF pages to doc
117
111
  converter.insertFromUrl2(host.concat(page1), settings);
118
- const is_conversion_1_successful = await converter.convert(doc);
112
+ await converter.convert(doc);
119
113
 
120
114
  // convert page 2 with different settings, appending generated PDF pages to doc
121
115
  const another_converter = await PDFNet.HTML2PDF.create();
@@ -123,14 +117,9 @@ const PDFTronLicense = require('../LicenseKey/LicenseKey');
123
117
  const another_settings = await PDFNet.HTML2PDF.WebPageSettings.create();
124
118
  another_settings.setPrintBackground(false);
125
119
  another_converter.insertFromUrl2(host.concat(page2), another_settings);
126
- const is_conversion_2_successful = await another_converter.convert(doc);
127
-
128
- if(is_conversion_0_successful && is_conversion_1_successful && is_conversion_2_successful) {
129
- doc.save(outputPath.concat('_03.pdf'), PDFNet.SDFDoc.SaveOptions.e_linearized);
130
- } else {
131
- console.log('Conversion failed. HTTP Code: ' + await html2pdf.getHttpErrorCode());
132
- console.log(await html2pdf.getLog());
133
- }
120
+ await another_converter.convert(doc);
121
+
122
+ doc.save(outputPath.concat('_03.pdf'), PDFNet.SDFDoc.SaveOptions.e_linearized);
134
123
  } catch (err) {
135
124
  console.log(err);
136
125
  }
@@ -144,12 +133,22 @@ const PDFTronLicense = require('../LicenseKey/LicenseKey');
144
133
  const html = '<html><body><h1>Heading</h1><p>Paragraph.</p></body></html>';
145
134
 
146
135
  html2pdf.insertFromHtmlString(html);
147
- if (await html2pdf.convert(doc)) {
148
- doc.save(outputPath.concat('_04.pdf'), PDFNet.SDFDoc.SaveOptions.e_linearized);
149
- } else {
150
- console.log('Conversion failed. HTTP Code: ' + await html2pdf.getHttpErrorCode());
151
- console.log(await html2pdf.getLog());
152
- }
136
+ await html2pdf.convert(doc);
137
+ doc.save(outputPath.concat('_04.pdf'), PDFNet.SDFDoc.SaveOptions.e_linearized);
138
+ } catch (err) {
139
+ console.log(err);
140
+ }
141
+
142
+ //--------------------------------------------------------------------------------
143
+ // Example 5) Set the location of the log file to be used during conversion.
144
+
145
+ try {
146
+ const html2pdf = await PDFNet.HTML2PDF.create();
147
+ const doc = await PDFNet.PDFDoc.create();
148
+ html2pdf.setLogFilePath('../TestFiles/Output/html2pdf.log');
149
+ html2pdf.insertFromUrl(host.concat(page0));
150
+ await html2pdf.convert(doc);
151
+ doc.save(outputPath.concat('_05.pdf'), PDFNet.SDFDoc.SaveOptions.e_linearized);
153
152
  } catch (err) {
154
153
  console.log(err);
155
154
  }