def PrintPdf(projectNo, probeInf, holelist, index=None): import os from config import basedir cptPath = os.path.join(basedir, 'app', 'static', 'download') if not os.path.exists(cptPath): os.makedirs(cptPath) doc = SimpleDocTemplate(cptPath, pagesize=A4, rightMargin=10, leftMargin=20, topMargin=30, bottomMargin=20 ) doc.pagesize = portrait(A4) filename = '' elements = [] for i in range(len(holelist)): if index is not None: i = index filename = projectNo + '__' + holelist[i].holeName + '.pdf' # Attenion:where elments.extend must be used,but not elements.append elements.extend(Cpt2Pdf(holelist[i], probeInf)) break; else: filename = projectNo + '__' + 'all.pdf' # Attenion:where elments.extend must be used,but not elements.append elements.extend(Cpt2Pdf(holelist[i], probeInf)) doc.filename = os.path.join(cptPath, filename) print("dd" + doc.filename) doc.build(elements) # url='/'.join(['download',projectNo,filename]) # os.path.join('download',projectNo,filename)将返回download\projectNo\filename,浏览器无法识别 return doc.filename
def PrintPdf(projectNo, probeInf, holelist, index=None): import os from config import basedir cptPath = os.path.join(basedir, 'app', 'static', 'download') if not os.path.exists(cptPath): os.makedirs(cptPath) doc = SimpleDocTemplate(cptPath, pagesize=A4, rightMargin=10, leftMargin=20, topMargin=30, bottomMargin=20) doc.pagesize = portrait(A4) filename = '' elements = [] for i in range(len(holelist)): if index is not None: i = index filename = projectNo + '__' + holelist[i].holeName + '.pdf' # Attenion:where elments.extend must be used,but not elements.append elements.extend(Cpt2Pdf(holelist[i], probeInf)) break else: filename = projectNo + '__' + 'all.pdf' # Attenion:where elments.extend must be used,but not elements.append elements.extend(Cpt2Pdf(holelist[i], probeInf)) doc.filename = os.path.join(cptPath, filename) print("dd" + doc.filename) doc.build(elements) # url='/'.join(['download',projectNo,filename]) # os.path.join('download',projectNo,filename)将返回download\projectNo\filename,浏览器无法识别 return doc.filename