【python】用python生成pdf文件
2017-04-21 17:27
274 查看
转自:https://www.davidfischer.name/2015/08/generating-pdfs-with-and-without-python/
from reportlab.platypus import SimpleDocTemplate, Paragraph from reportlab.lib.styles import getSampleStyleSheet from reportlab.lib.units import inch from reportlab.lib.pagesizes import letter import io def write_pdf_file(path, sentlist): buf = io.BytesIO() # Setup the document with paper size and margins doc = SimpleDocTemplate( buf, rightMargin=inch / 2, leftMargin=inch / 2, topMargin=inch / 2, bottomMargin=inch / 2, pagesize=letter, ) # Styling paragraphs styles = getSampleStyleSheet() # Write things on the document paragraphs = [] for sent in sentlist: if sent.strip() == '': sent = '_' paragraphs.append(Paragraph(sent, styles['Normal'])) doc.build(paragraphs) # Write the PDF to a file with open(path, 'w') as fd: fd.write(buf.getvalue()) if __name__ == '__main__': text=['a','b','c'] path='test.pdf' write_pdf_file(path,text)
相关文章推荐
- Python生成PDF文件(1)
- Python生成pdf文件的方法
- Python生成pdf文件的方法
- 利用Python的Django框架生成PDF文件的教程
- python 生成pdf文件
- python中解析和生成pdf文件
- python反编译chm文件并生成pdf文件
- Python数据生成pdf文件
- 利用Python的Django框架生成PDF文件的教程
- python生成pdf文件
- python中生成可执行文件的最好的办法是什么
- 生成PDF文件的Java库iText
- 从Java应用程序动态生成PDF文件
- 用C#代码生成一个简单的PDF文件
- Microstation生成PDF文件
- 用C#代码生成一个简单的PDF文件
- 用PHP生成PDF文件 with FPDF
- 利用PDFLIB开发库生成PDF文件
- 利用PDFLIB开发库生成PDF文件
- 从 Java 应用程序动态生成 PDF 文件(摘)