chore: disable puppeteer
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// const { getPdfBuffer } = require('./puppeteer');
|
||||
const { marked } = require('marked');
|
||||
const puppeteer = require('puppeteer');
|
||||
// const puppeteer = require('puppeteer');
|
||||
|
||||
function getHtmlTemplate(body) {
|
||||
return `
|
||||
@@ -155,57 +155,58 @@ function getCourseBody({ courseTitle, orgName, orgTheme, lessons }) {
|
||||
}
|
||||
|
||||
async function generateSinglePdfFromHtml(htmlContent, courseTitle, orgTheme) {
|
||||
const args = [
|
||||
'--disable-web-security',
|
||||
'--no-sandbox',
|
||||
'--disable-setuid-sandbox',
|
||||
];
|
||||
const browser = await puppeteer.launch({
|
||||
headless: 'new',
|
||||
args,
|
||||
});
|
||||
const page = await browser.newPage();
|
||||
throw 'Download disabled';
|
||||
// const args = [
|
||||
// '--disable-web-security',
|
||||
// '--no-sandbox',
|
||||
// '--disable-setuid-sandbox',
|
||||
// ];
|
||||
// const browser = await puppeteer.launch({
|
||||
// headless: 'new',
|
||||
// args,
|
||||
// });
|
||||
// const page = await browser.newPage();
|
||||
|
||||
await page.setContent(htmlContent);
|
||||
// await page.setContent(htmlContent);
|
||||
|
||||
const pdfOptions = {
|
||||
format: 'A4',
|
||||
printBackground: true,
|
||||
displayHeaderFooter: true,
|
||||
headerTemplate:
|
||||
"<div><div class='pageNumber'></div> <div>/</div><div class='totalPages'></div></div>",
|
||||
footerTemplate: `
|
||||
<div class="footer" style="position: relative; display: flex; text-align: right; margin-right: 5%; font-size: 8px; width: 297mm; padding-top: 30px;">
|
||||
<div style="position: absolute; right: 50%; bottom: 3%;"><span class="pageNumber"></span>/<span class="totalPages"></span></div>
|
||||
<div style="position: absolute; right: 0; bottom: 3%;">${courseTitle} | Powered by <a href="https://app.classroomio.com" style="text-decoration: underline;">ClassroomIO</a></div>
|
||||
</div>
|
||||
`,
|
||||
margin: {
|
||||
top: '0.3cm',
|
||||
bottom: '0.5cm',
|
||||
},
|
||||
};
|
||||
// const pdfOptions = {
|
||||
// format: 'A4',
|
||||
// printBackground: true,
|
||||
// displayHeaderFooter: true,
|
||||
// headerTemplate:
|
||||
// "<div><div class='pageNumber'></div> <div>/</div><div class='totalPages'></div></div>",
|
||||
// footerTemplate: `
|
||||
// <div class="footer" style="position: relative; display: flex; text-align: right; margin-right: 5%; font-size: 8px; width: 297mm; padding-top: 30px;">
|
||||
// <div style="position: absolute; right: 50%; bottom: 3%;"><span class="pageNumber"></span>/<span class="totalPages"></span></div>
|
||||
// <div style="position: absolute; right: 0; bottom: 3%;">${courseTitle} | Powered by <a href="https://app.classroomio.com" style="text-decoration: underline;">ClassroomIO</a></div>
|
||||
// </div>
|
||||
// `,
|
||||
// margin: {
|
||||
// top: '0.3cm',
|
||||
// bottom: '0.5cm',
|
||||
// },
|
||||
// };
|
||||
|
||||
const numPages = await page.evaluate(() => {
|
||||
const content = document.body; // Change this to the specific element containing content
|
||||
const style = window.getComputedStyle(content);
|
||||
const contentHeight = parseInt(style.height, 10);
|
||||
const pageHeight = 900; // Set this to an appropriate value based on your PDF format
|
||||
// const numPages = await page.evaluate(() => {
|
||||
// const content = document.body; // Change this to the specific element containing content
|
||||
// const style = window.getComputedStyle(content);
|
||||
// const contentHeight = parseInt(style.height, 10);
|
||||
// const pageHeight = 900; // Set this to an appropriate value based on your PDF format
|
||||
|
||||
return Math.ceil(contentHeight / pageHeight);
|
||||
});
|
||||
// return Math.ceil(contentHeight / pageHeight);
|
||||
// });
|
||||
|
||||
const pagesPdfBuffer = [];
|
||||
// const pagesPdfBuffer = [];
|
||||
|
||||
for (let currentPage = 1; currentPage <= numPages; currentPage++) {
|
||||
await page.evaluate(() => {});
|
||||
// for (let currentPage = 1; currentPage <= numPages; currentPage++) {
|
||||
// await page.evaluate(() => {});
|
||||
|
||||
const pdfBuffer = await page.pdf(pdfOptions);
|
||||
pagesPdfBuffer.push(pdfBuffer);
|
||||
}
|
||||
// const pdfBuffer = await page.pdf(pdfOptions);
|
||||
// pagesPdfBuffer.push(pdfBuffer);
|
||||
// }
|
||||
|
||||
await browser.close();
|
||||
return Buffer.concat(pagesPdfBuffer);
|
||||
// await browser.close();
|
||||
// return Buffer.concat(pagesPdfBuffer);
|
||||
}
|
||||
|
||||
async function generateCoursePdf(params) {
|
||||
@@ -217,5 +218,5 @@ async function generateCoursePdf(params) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
generateCoursePdf,
|
||||
generateCoursePdf
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// const { getPdfBuffer } = require('./puppeteer');
|
||||
const { marked } = require('marked');
|
||||
const puppeteer = require('puppeteer');
|
||||
// const puppeteer = require('puppeteer');
|
||||
|
||||
function getHtmlTemplate(body) {
|
||||
return `
|
||||
@@ -75,15 +75,7 @@ function getHtmlTemplate(body) {
|
||||
`;
|
||||
}
|
||||
|
||||
function getLessonBody({
|
||||
title,
|
||||
number,
|
||||
orgName,
|
||||
note,
|
||||
slideUrl,
|
||||
video,
|
||||
courseTitle,
|
||||
}) {
|
||||
function getLessonBody({ title, number, orgName, note, slideUrl, video, courseTitle }) {
|
||||
const noteHtml = marked.parse(note);
|
||||
const showExtraResources = slideUrl || (video && video.length > 0);
|
||||
return `
|
||||
@@ -148,54 +140,56 @@ function getLessonBody({
|
||||
}
|
||||
|
||||
async function generateSinglePdfFromHtml(htmlContent, courseTitle) {
|
||||
const args = [
|
||||
'--disable-web-security',
|
||||
'--no-sandbox',
|
||||
'--disable-setuid-sandbox',
|
||||
];
|
||||
const browser = await puppeteer.launch({
|
||||
headless: 'new',
|
||||
args,
|
||||
});
|
||||
const page = await browser.newPage();
|
||||
// const args = [
|
||||
// '--disable-web-security',
|
||||
// '--no-sandbox',
|
||||
// '--disable-setuid-sandbox',
|
||||
// ];
|
||||
// const browser = await puppeteer.launch({
|
||||
// headless: 'new',
|
||||
// args,
|
||||
// });
|
||||
// const page = await browser.newPage();
|
||||
|
||||
await page.setContent(htmlContent);
|
||||
// await page.setContent(htmlContent);
|
||||
|
||||
const pdfOptions = {
|
||||
format: 'A4',
|
||||
printBackground: true,
|
||||
displayHeaderFooter: true,
|
||||
headerTemplate:
|
||||
"<div><div class='pageNumber'></div> <div>/</div><div class='totalPages'></div></div>",
|
||||
footerTemplate: `<div class="footer" style="text-align: right; margin-right: 5%; font-size: 8px; width: 297mm; padding-top: 30px;">
|
||||
${courseTitle} | Powered by <a href="https://app.classroomio.com" style="color: blue; text-decoration: underline;">ClassroomIO</a>
|
||||
</div>`,
|
||||
margin: {
|
||||
top: '0.4cm',
|
||||
bottom: '1cm',
|
||||
},
|
||||
};
|
||||
// const pdfOptions = {
|
||||
// format: 'A4',
|
||||
// printBackground: true,
|
||||
// displayHeaderFooter: true,
|
||||
// headerTemplate:
|
||||
// "<div><div class='pageNumber'></div> <div>/</div><div class='totalPages'></div></div>",
|
||||
// footerTemplate: `<div class="footer" style="text-align: right; margin-right: 5%; font-size: 8px; width: 297mm; padding-top: 30px;">
|
||||
// ${courseTitle} | Powered by <a href="https://app.classroomio.com" style="color: blue; text-decoration: underline;">ClassroomIO</a>
|
||||
// </div>`,
|
||||
// margin: {
|
||||
// top: '0.4cm',
|
||||
// bottom: '1cm',
|
||||
// },
|
||||
// };
|
||||
|
||||
const numPages = await page.evaluate(() => {
|
||||
const content = document.body; // Change this to the specific element containing content
|
||||
const style = window.getComputedStyle(content);
|
||||
const contentHeight = parseInt(style.height, 10);
|
||||
const pageHeight = 900; // Set this to an appropriate value based on your PDF format
|
||||
// const numPages = await page.evaluate(() => {
|
||||
// const content = document.body; // Change this to the specific element containing content
|
||||
// const style = window.getComputedStyle(content);
|
||||
// const contentHeight = parseInt(style.height, 10);
|
||||
// const pageHeight = 900; // Set this to an appropriate value based on your PDF format
|
||||
|
||||
return Math.ceil(contentHeight / pageHeight);
|
||||
});
|
||||
// return Math.ceil(contentHeight / pageHeight);
|
||||
// });
|
||||
|
||||
const pagesPdfBuffer = [];
|
||||
// const pagesPdfBuffer = [];
|
||||
|
||||
for (let currentPage = 1; currentPage <= numPages; currentPage++) {
|
||||
await page.evaluate(() => {});
|
||||
// for (let currentPage = 1; currentPage <= numPages; currentPage++) {
|
||||
// await page.evaluate(() => {});
|
||||
|
||||
const pdfBuffer = await page.pdf(pdfOptions);
|
||||
pagesPdfBuffer.push(pdfBuffer);
|
||||
}
|
||||
// const pdfBuffer = await page.pdf(pdfOptions);
|
||||
// pagesPdfBuffer.push(pdfBuffer);
|
||||
// }
|
||||
|
||||
await browser.close();
|
||||
return Buffer.concat(pagesPdfBuffer);
|
||||
// await browser.close();
|
||||
// return Buffer.concat(pagesPdfBuffer);
|
||||
|
||||
throw 'Download disabled';
|
||||
}
|
||||
|
||||
async function generateLessonPdf(params) {
|
||||
@@ -223,5 +217,5 @@ async function generateLessonPdf(params) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
generateLessonPdf,
|
||||
generateLessonPdf
|
||||
};
|
||||
|
||||
@@ -1,38 +1,39 @@
|
||||
const puppeteer = require('puppeteer');
|
||||
// const puppeteer = require('puppeteer');
|
||||
|
||||
const getPdfBuffer = async (html, pdfParams) => {
|
||||
const args = [
|
||||
'--disable-web-security',
|
||||
'--no-sandbox',
|
||||
'--disable-setuid-sandbox',
|
||||
];
|
||||
const defaultPdfParams = {
|
||||
width: '1123px',
|
||||
height: '794px',
|
||||
};
|
||||
throw 'Puppeteer disabled';
|
||||
// const args = [
|
||||
// '--disable-web-security',
|
||||
// '--no-sandbox',
|
||||
// '--disable-setuid-sandbox',
|
||||
// ];
|
||||
// const defaultPdfParams = {
|
||||
// width: '1123px',
|
||||
// height: '794px',
|
||||
// };
|
||||
|
||||
// launch a new chrome instance
|
||||
const browser = await puppeteer.launch({
|
||||
headless: 'new',
|
||||
args,
|
||||
});
|
||||
// // launch a new chrome instance
|
||||
// const browser = await puppeteer.launch({
|
||||
// headless: 'new',
|
||||
// args,
|
||||
// });
|
||||
|
||||
// create a new page
|
||||
const page = await browser.newPage();
|
||||
await page.setViewport({ width: 1123, height: 794 });
|
||||
await page.goto('data:text/html,' + html, { waitUntil: 'networkidle2' });
|
||||
await page.addStyleTag({ content: '@page { size: auto; }' });
|
||||
await page.emulateMediaType('screen');
|
||||
// // create a new page
|
||||
// const page = await browser.newPage();
|
||||
// await page.setViewport({ width: 1123, height: 794 });
|
||||
// await page.goto('data:text/html,' + html, { waitUntil: 'networkidle2' });
|
||||
// await page.addStyleTag({ content: '@page { size: auto; }' });
|
||||
// await page.emulateMediaType('screen');
|
||||
|
||||
// create a pdf buffer
|
||||
const pdfBuffer = await page.pdf(pdfParams || defaultPdfParams);
|
||||
// // create a pdf buffer
|
||||
// const pdfBuffer = await page.pdf(pdfParams || defaultPdfParams);
|
||||
|
||||
// close the browser
|
||||
await browser.close();
|
||||
// // close the browser
|
||||
// await browser.close();
|
||||
|
||||
return pdfBuffer;
|
||||
// return pdfBuffer;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getPdfBuffer,
|
||||
getPdfBuffer
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user