Save a webpage to a PDF file using Actor.setValue(...
# crawlee-js
d
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:
Copy code
javascript
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 https://cdn.discordapp.com/attachments/1287687792654290947/1287687793010675743/image.png?ex=66f27435&is=66f122b5&hm=4acc5ee0b09c5daf7faca833ac9a0339e87b511c46a9474dd3b9da463ad9de4d&
h
message has been deleted
r
hey, the
pdf()
method [returns](https://pptr.dev/api/puppeteer.page.pdf)
Uint8Array
, you will need to convert it to a
Buffer
class, try this:
Copy code
ts
const pdfFileName = 'testFile';
const pdf = await page.pdf({ format: 'A4', printBackground: true });
const pdfBuffer = Buffer.from(pdf);

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