這篇文章給大家分享的是有關python如何編寫一個簡單的WSGI PDF server的內容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
創(chuàng)新互聯(lián)公司是一家專注于成都做網(wǎng)站、成都網(wǎng)站建設與策劃設計,鎮(zhèn)寧網(wǎng)站建設哪家好?創(chuàng)新互聯(lián)公司做網(wǎng)站,專注于網(wǎng)站建設10余年,網(wǎng)設計領域的專業(yè)建站公司;建站業(yè)務涵蓋:鎮(zhèn)寧等地區(qū)。鎮(zhèn)寧做網(wǎng)站價格咨詢:13518219792
示例:
# basic_wsgi_pdf_server.py # Basic WSGI PDF server in Python. # Adapted from: from PDFWriter import PDFWriter from wsgiref.simple_server import make_server host = 'localhost' port = 8888 def app(environ, start_response): path = environ['PATH_INFO'] method = environ['REQUEST_METHOD'] print "path:", path print "method:", method #response = 'This is the page for "{}"'.format(path) lines = [ "Jack and Jill went up the hill", "Humpty Dumpty sat on a wall,", "'You are old, Father William,' the young man said,", "Master of all masters" ] pdf_filename = "Nursery-rhymes-and-stories.pdf" pw = PDFWriter(pdf_filename) pw.setFont("Courier", 12) pw.setHeader("Excerpts from nursery rhymes and stories") pw.setFooter("Generated by xtopdf and basic_wsgi_pdf_server") for line in lines: pw.writeLine(line) pw.writeLine(" ") pw.close() with open(pdf_filename, "rb") as fil: response = fil.read() #start_response('200 OK', [('Content-type', 'text/html')]) start_response('200 OK', [('Content-type', 'application/pdf')]) return [response] make_server(host, port, app).serve_forever() 在命令行下運行下面的代碼開啟服務: pythonbasic_wsgi_pdf_server.py
感謝各位的閱讀!關于“python如何編寫一個簡單的WSGI PDF server”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!