django中Html转PDF
来源:互联网 发布:三a甲级数据分析事务所 编辑:程序博客网 时间:2024/05/16 08:25
利用pdfcrowd 实现HTML转 PDF的功能
(1)环境:ubuntu12.04/python 2.7.8/Django 1.7
(2)安装
$ pip install pdfcrowd
或者fork下安装包,然后安装
python setup.py install(3)注册
点击打开链接
(4)使用
import pdfcrowdfrom django.http import HttpResponsedef generate_pdf_view(request): username = 'username' apikey = 'apikey' try: # create an API client instance client = pdfcrowd.Client(username, apikey) # convert a web page and store the generated PDF to a variable pdf = client.convertURI("http://www.baidu.com") # 或者根据Html或本地文件转换 # pdf = client.convertHtml('<head></head><body>My Page</body>') # pdf = clent.convertFile('/var/www/xxx.html') # 必须是绝对路径 # set HTTP response headers # response = HttpResponse(mimetype="application/pdf") # 注意:新版本的django HttpResponse不支持mimetype,改成了content_type response = HttpResponse(content_type="application/pdf") response["Cache-Control"] = "max-age=0" response["Accept-Ranges"] = "none" response["Content-Disposition"] = "attachment; filename=xxx.pdf" # send the generated PDF response.write(pdf) except pdfcrowd.Error, why: response = HttpResponse(mimetype="text/plain") response.write(why) return response
上图:
0 0
- django中Html转PDF
- Django中生成PDF(一)
- Java Html 转Pdf
- Java Html 转Pdf
- HTML转PDF
- html 转 pdf
- Java html转PDF
- java html转pdf
- [PHP] HTML转PDF
- html转pdf文件
- Java HTML 转 PDF
- HTML转PDF
- HTML转pdf
- Java html转PDF
- HTML转PDF总结
- html转pdf
- html转pdf
- HTML转PDF问题
- 最后的旅程:美公司提供大气层抛撒骨灰服务
- 第八周本周有多少天
- inner join/left join/right join/full join
- 进程控制之exit和waitpid(wait)函数
- 写clone()方法时,通常都有一行代码,是什么?
- django中Html转PDF
- 菜鸟学习Spring——60s使用annotation实现简单AOP
- 将string字符串中的字符转为全部大写或者全部小写
- [Leetcode] Maximum Subarray
- 个人总结openflow与controller
- Python循环语句(while)
- Android ADB的使用方法
- Android NDK的C++11标准支持
- 一些常用的Bootstrap模板资源站