0

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());
}
  • Nothing in this code creates a screenshot or image of the website. All you're doing is putting the raw HTML into your file. You will either need to use a library that can make a screenshot of the website or a library that can convert HTML to PDF or something similar. – jfriend00 Jan 20 '21 at 17:34
  • So it's not possible to use cheerio to do this? – berry_malicious Jan 28 '21 at 23:23

1 Answers1

1

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)

jfriend00
  • 683,504
  • 96
  • 985
  • 979