-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathurl-conversion.js
More file actions
55 lines (45 loc) · 1.31 KB
/
url-conversion.js
File metadata and controls
55 lines (45 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
* URL-based conversion example
*
* Convert a website or online file directly from URL
* without uploading a file first.
*/
const { ConversionToolsClient } = require('conversiontools');
const apiToken = process.env.CONVERSION_TOOLS_API_TOKEN || 'your-api-token-here';
async function main() {
const client = new ConversionToolsClient({
apiToken,
});
try {
console.log('Converting website to PDF...');
// Convert website to PDF
const outputPath = await client.convert({
type: 'convert.website_to_pdf',
input: { url: 'https://conversiontools.io' },
output: './website.pdf',
options: {
images: true,
javascript: true,
orientation: 'Portrait',
pagesize: 'A4',
},
});
console.log(`✓ Website saved to PDF: ${outputPath}`);
// Convert online image to different format
console.log('\nConverting website to image...');
const imagePath = await client.convert({
type: 'convert.website_to_png',
input: { url: 'https://conversiontools.io' },
output: './website.png',
options: {
images: true,
javascript: true,
},
});
console.log(`✓ Website saved to image: ${imagePath}`);
} catch (error) {
console.error('✗ Error:', error.message);
process.exit(1);
}
}
main();