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();
Actor.setValue
doesn't want to consume the sent PDF buffer. What am I doing wrong?pdf()
method returns Uint8Array
, you will need to convert it to a Buffer
class, try this: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' });