//printing section function checkBlob(){ print("checkBlob: "+config.blob); if (config.blob) { clearInterval(config.blobInterval); config.a.href = config.window.URL.createObjectURL(config.blob); print("HREF: "+config.a.href); config.a.download = 'test.pdf'; config.a.click(); config.window.URL.revokeObjectURL(config.a.href); } config.count=config.count+1; print("Eval: "+config.count); if (config.count>100){ clearInterval(config.blobInterval); } } function printForm(){ config.doc=new PDFDocument(); //config.doc.end(); let stream = config.doc.pipe(blobStream()).on("finish",function(){ config.blob=stream.toBlob("application/pdf");}); print("BLob: "+config.blob); config.a = config.document.createElement("a"); config.document.body.appendChild(config.a); config.a.innerHTML="Download PDF"; config.a.style = "display: none"; config.count=0; //run until blob is set config.blobInterval=setInterval(checkBlob,1000); //pick data from crfForm list print("Printing form"); printHeader(); setData(formatPrintData); } function printHeader(){ config.doc.fontSize(25).text(config.formConfig.form['formName']); config.doc.moveDown(); let crfEntry=config.formConfig.crfEntry; let site=config.formConfig.currentSite; let val=new Object(); let user=config.formConfig.user; val['A']={o:crfEntry,f:'EudraCTNumber',t:'Eudra CT Number'}; val['B']={o:crfEntry,f:'StudyCoordinator',t:'Study Coordinator'}; val['C']={o:crfEntry,f:'StudySponsor',t:'Study Sponsor'}; val['D']={o:site,f:'siteName',t:'Site'}; val['E']={o:site,f:'sitePhone',t:'Phone'}; val['F']={o:user,f:'DisplayName',t:'Investigator'}; for (let f in val){ print('Printing for '+f); let e=val[f]; let entry=new Object(); entry[f]=e.o[e.f]; printPDF(entry, {name:f,caption:e.t,type:'string'},null); } config.doc.moveDown(); } function formatPrintData(){ qS=config.formConfig.dataQueries; for (let q in qS){ print('Setting up '+q); let qData=qS[q]; print('Number of rows: '+qData.rows.length); if (qData.rows.length>0){ config.doc.fontSize(20).text(qData.title); } for (let i=0;i