// const { getPdfBuffer } = require('./puppeteer');
const { marked } = require('marked');
// const puppeteer = require('puppeteer');
function getHtmlTemplate(body) {
return `
Lesson Note
${body}
`;
}
function getLessonBody({ title, number, orgName, note, slideUrl, video, courseTitle }) {
const noteHtml = marked.parse(note);
const showExtraResources = slideUrl || (video && video.length > 0);
return `
${number}
${title}
By ${orgName}
${
showExtraResources
? `
Extra Resources
${
slideUrl
? ``
: ''
}
${
video && video.length > 0
? `
Video Link:
${video
.map(
(videoData, index) => `
- ${videoData}
`
)
.join('')}
`
: ''
}
`
: ''
}
`;
}
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();
// await page.setContent(htmlContent);
// const pdfOptions = {
// format: 'A4',
// printBackground: true,
// displayHeaderFooter: true,
// headerTemplate:
// "",
// footerTemplate: ``,
// 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
// return Math.ceil(contentHeight / pageHeight);
// });
// const pagesPdfBuffer = [];
// for (let currentPage = 1; currentPage <= numPages; currentPage++) {
// await page.evaluate(() => {});
// const pdfBuffer = await page.pdf(pdfOptions);
// pagesPdfBuffer.push(pdfBuffer);
// }
// await browser.close();
// return Buffer.concat(pagesPdfBuffer);
throw 'Download disabled';
}
async function generateLessonPdf(params) {
// Generate the lesson boddy
const body = getLessonBody(params);
const html = getHtmlTemplate(body);
console.log(html);
return await generateSinglePdfFromHtml(html, params.courseTitle);
// return await getPdfBuffer(html, {
// path: 'test.pdf',
// width: '1000px',
// height: undefined,
// printBackground: true,
// format: 'A4',
// displayHeaderFooter: true,
// headerTemplate:
// "",
// footerTemplate:
// ' of
',
// margin: {
// top: '1cm',
// bottom: '1cm',
// },
// });
}
module.exports = {
generateLessonPdf
};