How to convert a website to pdf with cheerio and fs

623 Views Asked by At

I'm trying to get a pdf document from a website but I keep getting the code on the pdf instead of pictures or "screenshots" of it. I want to stick to cheerio and fs.

this is where it saves.

const pdf_completo = fs.createWriteStream('paginas/pdf_completo.pdf');

This is the function im trying to use to obtain it.

async function obtener_pdf_pagina(){
    const $ = await request({
        uri: 'http://quotes.toscrape.com/',
        transform: pdf => cheerio.load(pdf)
    });
    const todo_pagina = $('*');
    pdf_completo.write(todo_pagina.html());
}
1

There are 1 best solutions below

0
On BEST ANSWER

I don't think cheerio has any sort of screenshot capability. Cheerio parses the HTML and gives you a DOM-like API you can interact with, but doesn't actually render anything on a screen.

As best I know, you would need something like puppeteer to do screenshots (which uses the chromium browser engine to render)