Apify and Crawlee Official Forum

Home
Members
David Cizek
D
David Cizek
Offline, last seen 3 months ago
Joined September 23, 2024
Hi, I'm new to PuppeteerCrawler. I'm trying to create a simple script to save a webpage as a PDF. For this purpose, I created a new Actor from the Crawlee - Puppeteer - TypeScript template in Apify. This is my main.ts code:
Plain Text
import { Actor } from 'apify';
import { PuppeteerCrawler, Request } from 'crawlee';

await Actor.init();

interface Input {
    urls: Request[];
}

const { urls = ['https://www.google.com/'] } = await Actor.getInput<Input>() ?? {};

const crawler = new PuppeteerCrawler({
    async requestHandler({ page }) {
        const pdfFileName = 'testFile';
        const pdfBuffer = await page.pdf({ format: 'A4', printBackground: true });

        console.log('pdfFileName: ', pdfFileName);
        console.log('pdfBuffer: ', pdfBuffer);
        
        await Actor.setValue(pdfFileName, pdfBuffer, { contentType: 'application/pdf' });
    },
});

await crawler.addRequests(urls);
await crawler.run();

await Actor.exit();


It seems that Actor.setValue doesn't want to consume the sent PDF buffer. What am I doing wrong?
Thanks
2 comments
R
D