var crfPrint={}; //printing section // crfPrint.set= function(parentClass){ this.parent=parentClass; } crfPrint.checkBlob= function(){ this.parent.print("checkBlob: "+this.blob); if (this.blob) { clearInterval(this.blobInterval); this.a.href = this.parent.config.window.URL.createObjectURL(this.blob); this.parent.print("HREF: "+this.a.href); this.a.download = 'test.pdf'; this.a.click(); this.parent.config.window.URL.revokeObjectURL(this.a.href); } this.count=this.count+1; this.parent.print("Eval: "+this.count); if (this.count>100){ clearInterval(this.blobInterval); } } crfPrint.printForm= function(){ let that=this; let action=function(){that.afterScripts();}; LABKEY.Utils.requiresScript(["crfTecant/blob-stream.js","crfTecant/pdfkit.standalone.js"],action); } crfPrint.afterScripts= function(){ let config=this.parent.config; this.doc=new PDFDocument(); let that=this; //config.doc.end(); let action=function(){that.blob=that.stream.toBlob("application/pdf");}; this.stream = this.doc.pipe(blobStream()).on("finish",action); this.parent.print("BLob: "+this.blob); this.a = this.parent.config.document.createElement("a"); this.parent.config.document.body.appendChild(this.a); this.a.innerHTML="Download PDF"; this.a.style = "display: none"; this.count=0; //run until blob is set let iAction=function(){that.checkBlob();} this.blobInterval=setInterval(iAction,1000); //pick data from crfForm list this.parent.print("Printing form"); this.printHeader(); let foo=function(){that.formatPrintData();}; this.parent.setData(foo); } crfPrint.printHeader= function(){ let config=this.parent.config; this.doc.fontSize(25).text(config.formConfig.form['formName']); this.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){ this.parent.print('Printing for '+f); let e=val[f]; let entry=new Object(); entry[f]=e.o[e.f]; this.printPDF(entry, {name:f,caption:e.t,type:'string'},null); } this.doc.moveDown(); } crfPrint.formatPrintData= function(){ let config=this.parent.config; qS=this.parent.getQueryList(); for (let q in qS){ this.parent.print('Setting up '+q); let qData=this.parent.getQuerySnapshot(q); let qLayout=this.parent.getQueryLayout(q); this.parent.print('Number of rows: '+qData.rows.length); if (qData.rows.length>0){ this.doc.fontSize(20).text(qLayout.title); } let fields=qLayout.fields; for (let i=0;i