You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Scroll down to the bottom of the document to make sure all pages have loaded.
Open Developer Tools - Console:
If you are previewing in Google Chrome or Firefox: Press Shift + Ctrl + J ( on Windows / Linux) or Option + ⌘ + J (on Mac).
If you are previewing in Microsoft Edge Press Shift + Ctrl + I.
If you are previewing in Apple Safari Press Option + ⌘ + C.
Paste below code and press Enter. The pdf file will now start downloading. This may take a few minutes depending on the number of pages in the document.
lettrustedURL_jspdf;lettrustedURL_domtoimage;if(window.trustedTypes&&trustedTypes.createPolicy){constpolicy=trustedTypes.createPolicy('myPolicy',{createScriptURL: (input)=>input});trustedURL_jspdf=policy.createScriptURL('https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.4.0/jspdf.umd.min.js');trustedURL_domtoimage=policy.createScriptURL('https://cdnjs.cloudflare.com/ajax/libs/dom-to-image/2.6.0/dom-to-image.min.js');}else{trustedURL_jspdf='https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.4.0/jspdf.umd.min.js';trustedURL_domtoimage='https://cdnjs.cloudflare.com/ajax/libs/dom-to-image/2.6.0/dom-to-image.min.js';}constscript1=document.createElement('script');script1.src=trustedURL_jspdf;document.head.appendChild(script1);constscript2=document.createElement('script');script2.src=trustedURL_domtoimage;document.head.appendChild(script2);script1.onload=script2.onload=function(){if(window.jspdf&&window.domtoimage){console.log('Both libraries loaded successfully');createPDFWithImages();}else{console.error('Failed to load the libraries');}};asyncfunctiontranslateText(text,sourceLang='auto',targetLang='fr'){//translate to frenchconsturl=`https://translate.googleapis.com/translate_a/single?client=gtx&sl=${sourceLang}&tl=${targetLang}&dt=t&q=${encodeURIComponent(text)}`;try{constresponse=awaitfetch(url);constdata=awaitresponse.json();consttranslatedText=data[0].map(item=>item[0]).join(' ');returntranslatedText;}catch(error){console.error('Translate error:',error);returnnull;}}functiongetSlideNotesText(slideNotes){if(!slideNotes){console.log('Not found: class "slide-notes"');return'';}constparagraphs=slideNotes.querySelectorAll('p');consttextContent=Array.from(paragraphs).map(p=>p.textContent.trim()).join(' \n ');returntextContent;}constcreatePDFWithImages=async()=>{const{
jsPDF
}=window.jspdf;constdoc=newjsPDF({orientation: 'l',unit: 'mm',format: 'a4',compressPDF: true});constslides=document.querySelectorAll('div.slide');constpageWidth=doc.internal.pageSize.getWidth();constpageHeight=doc.internal.pageSize.getHeight();constmargin=0;for(leti=0;i<slides.length;i++){constslide=slides[i];constcontent=slide.querySelector('.slide-content');constnotes=slide.querySelector('.slide-notes');content.style.margin='0';awaitwindow.domtoimage.toPng(content).then((imgDataUrl)=>{if(i>0){doc.addPage();}constimgWidth=pageWidth-2*margin;constimgHeight=imgWidth*(content.clientHeight/content.clientWidth);constx=margin;consty=(pageHeight-imgHeight)/2;doc.addImage(imgDataUrl,'PNG',x,y,imgWidth,imgHeight,'','FAST');}).catch((error)=>{console.error('Failed to convert slide to image:',error);});if(notes!=undefined){notes.style.margin='0';consttxtNotes=" "+getSlideNotesText(notes);consttranslatedResult=awaittranslateText(txtNotes);constcombinedNote=txtNotes+"\n\nTranslated text: \n\n "+translatedResult;doc.addPage();doc.text(combinedNote,10,10,{maxWidth: pageWidth-20});}}doc.save('slides.pdf');};
absolutely goated