I have a website that converts HTML to PDF files using a library in Django called " XHTML2PDF ".
The problem is that I need to convert this PDF file using the PDF / X-1a format . I don't know if it is possible to change the format in XHTML2PDF, if not, does anyone know an alternative?
View:
def book(request):
data = {}
data['today'] = datetime.date.today()
data['farmer'] = 'Old MacDonald'
data['animals'] = [('Cow', 'Moo'), ('Goat', 'Baa'), ('Pig', 'Oink')]
template = get_template('book_number_one.html')
html = template.render(Context(data))
file = open('test.pdf', "w+b")
pisaStatus = pisa.CreatePDF(html.encode('utf-8'), dest=file,
encoding='utf-8')
file.seek(0)
pdf = file.read()
file.close()
return HttpResponse(pdf, mimetype='application/pdf')
Template:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Background</title>
<style>
@page p1 {
background-image: url("nu/COVER-FRONT-ES.png");
size: 210mm 210mm;
@frame text {
top: 6cm;
left: 4cm;
right: 4cm;
bottom: 4cm;
}
}
@page p2 {
background-image: url("nu/001.png");
size: 210mm 210mm;
@frame text {
top: 6cm;
left: 4cm;
right: 4cm;
bottom: 4cm;
border:0;
}
}
@font-face {
font-family: 'Gilles';
src: url(/gilles/gilles.ttf);
font-weight: normal;
font-style: normal;
}
</style>
</head>
<body>
<pdf:nextpage name="p1" />
<pdf:nextpage name="p2" />
<p class="page-2">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. <br />
Vitae, natus, possimus, placeat consequuntur iste at sapiente perferendis <br />
delectus suscipit dolorem dignissimos quaerat quia ex fuga officia dolore <br />
asperiores sint mollitia.<br />
<br />
</p>
</body>
</html>
source
share