30 lines
985 B
JavaScript
30 lines
985 B
JavaScript
import { BrowserToolBase } from './base.js';
|
|
import { createSuccessResponse } from '../common/types.js';
|
|
import * as path from 'path';
|
|
/**
|
|
* Tool for saving page as PDF
|
|
*/
|
|
export class SaveAsPdfTool extends BrowserToolBase {
|
|
/**
|
|
* Execute the save as PDF tool
|
|
*/
|
|
async execute(args, context) {
|
|
return this.safeExecute(context, async (page) => {
|
|
const filename = args.filename || 'page.pdf';
|
|
const options = {
|
|
path: path.resolve(args.outputPath || '.', filename),
|
|
format: args.format || 'A4',
|
|
printBackground: args.printBackground !== false,
|
|
margin: args.margin || {
|
|
top: '1cm',
|
|
right: '1cm',
|
|
bottom: '1cm',
|
|
left: '1cm'
|
|
}
|
|
};
|
|
await page.pdf(options);
|
|
return createSuccessResponse(`Saved page as PDF: ${options.path}`);
|
|
});
|
|
}
|
|
}
|