简体   繁体   中英

Usage of chrome headless for making PDF (puppeteer)

I wondering how can I get PDF using Chrome Headless (for example puppeteer). It seems like a good PDF maker but only on chrome using @media print. So here is my question:

Can I get PDF by puppeteer on another browser (ie, mozilla) too? I think I can do that if I want print static page with no inputs. But if I have inputs for users and they are saving it on IE. Can I use this somehow?


Ok i downloaded the puppeteer. I've got the code:

$scope.aClick = function(){
        const puppeteer = require('puppeteer');

        (async () => {
          const browser = await puppeteer.launch();
          const page = await browser.newPage();
          await page.goto('/vUrl_form.html', {waitUntil: 'networkidle'});
          await page.pdf({path: 'images/asd.pdf', format: 'A4'});

          browser.close();
        })();
    };

and this can't still work (i don't know why, but app can't run).

否-Puppeteer仅适用于Chromium / Chrome。

Unfortunately Puppeteer only works with Chromium/Chrome.

If you want to use Headless Mozilla Firefox, you might consider checking this out https://developer.mozilla.org/en-US/Firefox/Headless_mode .

If you still want to use Puppeteer, here is a working snippet that creates a .pdf file:

const puppeteer = require('puppeteer');

(async() => {

const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://news.ycombinator.com', {waitUntil: 'networkidle'});
// page.pdf() is currently supported only in headless mode.
// @see https://bugs.chromium.org/p/chromium/issues/detail?id=753118
await page.pdf({
  path: 'hn.pdf',
  format: 'letter'
});

browser.close();

})();

Today it's possible to use firefox with puppeter https://firefox-puppeteer.readthedocs.io/en/master/ Maybe when people answered it wasn't. But I can't find url to pdf functionality. Just screenshots.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM