【发布时间】:2015-05-04 09:48:22
【问题描述】:
我想使用 wkhtmltopdf 创建一个具有不同方向的 pdf(例如:一个页面是纵向的,另一页是横向的,然后是纵向的),我在 css 中尝试过,但它不起作用。请帮助,在此先感谢.
我的意见.py
from django.views.generic.base import View
from wkhtmltopdf.views import PDFTemplateResponse
class pdf_view(View):
template = 'temp1.html'
filename = 'file1.pdf'
header_template='header_temp.html'
footer_template='footer_temp.html'
context= {'title': 'PDF GENERATION'}
def get(self, request):
response = PDFTemplateResponse(request=request,
template=self.template,
filename = self.filename,
header_template=self.header_template,
footer_template=self.footer_template,
context= self.context,
)
return response
我的模板.html
<html>
<head>
<meta charset="utf-8">
<title>{{ title }}</title>
<style type="text/css">
#landimg img{
margin-top:20px;
height:auto;
width:auto;
}
#portimg img{
height:auto;
width:auto;
margin-top:50px;
}
@page #port{
size:letter;
}
@page #land{
size:landscape;
}
</style>
</head>
<body>
<div id='port'>
<img src="/static/images/2_180_3.jpg" alt="" />
</div>
<div id='land'>
<img src="/static/images/land.JPG" alt="" />
</div>
</body>
</html>
@page css 在打印 pdf 时不起作用,默认为纵向。
【问题讨论】:
标签: django pdf wkhtmltopdf