Created
September 18, 2024 09:18
-
-
Save smadil997/8c3403ddb6d883228ef2384fb126f27f to your computer and use it in GitHub Desktop.
Create JS file for convert HTML file to JS file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const puppeteer = require('puppeteer') | |
async function generatePDFFile() { | |
// Catch all input parameter received from API | |
const cmdArguments = process.argv.slice(2); | |
const htmlContent = cmdArguments[0]; | |
const pdfPath = cmdArguments[1]; | |
// Here we need OS name for change default browser Executable path for print the PDF | |
let browser = await puppeteer.launch({devtools: true,executablePath: 'C://Program Files//Google//Chrome//Application//chrome.exe'}); // Change path according to your Chrome installation location | |
const page =await browser.newPage(); | |
await page.goto(htmlContent, { waitUntil: 'networkidle0', }); | |
const pdfFile = await page.pdf({ path: pdfPath, format: 'A4',preferCSSPageSize: true, }); | |
await browser.close(); | |
return pdfFile; | |
} | |
return generatePDFFile(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment