๐Ÿ“ท Node.js์—์„œ JavaScript๋ฅผ ์‚ฌ์šฉํ•œ ์Šคํฌ๋ฆฐ์ƒท์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด๊ธฐ(PDF ์ƒ์„ฑ)

3025 ๋‹จ์–ด puppeteerwebdevjavascript
์—์„œ ์šฐ๋ฆฌ๋Š” png ์Šคํฌ๋ฆฐ์ƒท์„ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ๋‹ค์–‘ํ•œ ํ˜•์‹์˜ PDF๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค!

// instead of calling await page.screenshot we now call
await page.pdf({
    path: 'codesnacks.pdf',
    format: 'A4'
})


์™„๋ฒฝ์„ ๊ธฐํ•˜๊ธฐ ์œ„ํ•ด A4 ํ˜•์‹์œผ๋กœ ์›น ํŽ˜์ด์ง€์˜ PDF๋ฅผ ์ƒ์„ฑํ•˜๋Š” ์ „์ฒด ์ฝ”๋“œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

// npm i puppeteer
const puppeteer = require('puppeteer');

// we're using async/await - so we need an async function, that we can run
const run = async () => {
  // open the browser and prepare a page
  const browser = await puppeteer.launch();
  const page = await browser.newPage();

  await page.goto('https://codesnacks.net/');

  await page.pdf({
    path: 'codesnacks.pdf',
    format: 'A4',
  });

  // close the browser
  await browser.close();
};

// run the async function
run();

์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ