I am using pdfkit python 0.6.1 with wkhtmltopdf 0.12.4 on both my local system and on ec2 server The Problem is everything is running as expected on local system but on aws css styling got changed
Here is the template code
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Pdf Generate html</title>
<style>
@font-face {
font-family: 'BoldFont';
src: url('http://127.0.0.1:8000/static/fonts/Champagne & Limousines Bold.ttf') format('truetype'); /* Chrome 4+, Firefox 3.5, Opera 10+, Safari 3—5 */
}
</style>
</head>
<body style="text-align:center ;font-family: 'BoldFont' ;line-height:30.5pt;position:absolute; margin:80px 72px; letter-spacing:0.275em;line-height: 1.7; text-transform: uppercase;">
<div id="svg_view" style="border: 7px solid #000; ">
<img src="http://127.0.0.1:8000/static/images/svg_img/test.svg" style="padding:75px">
<div class="product-des" id="product-header" style="font-size: 22.5pt;letter-spacing:0.281em; margin-top:-8px;">UNDER THESE STARS YOU WERE BORN<br>
LOVE YOU TO THE MOON AND BEYOND</div>
<div class="name" id="user_name" style=" font-size: 19.8pt; margin:115px 0px 134px 0">{{username}}</div>
<div class="product-des" id="product-des" style=" font-size: 15pt;margin-bottom:50px;letter-spacing:0.22em">
THE SKIES ABOVE Hadera, Israel<br> {{mth}} {{day}}th, {{year}} AT {{hrs}}:{{min}} AM<br> {{lat}}˚ N <span style="margin-left:18px">{{long}}˚ E</span>
</div>
</div>
</body>
</html>
Here is python code
template_name = "site/pdf_generate.html"
def get(self, request):
options = {
'page-size': 'A3',
'margin-top': '0',
'margin-right': '0',
'margin-bottom': '0',
'margin-left': '0',
'dpi': 300
}
context = {
'username':request.session.get("myname"),
'lat': request.session.get("lat"),
'long': request.session.get("long"),
'msg': request.session.get("msg"),
'mth': request.session.get("mth"),
'day': request.session.get("day"),
'year': request.session.get("year"),
'hrs': request.session.get("hrs"),
'min': request.session.get("min"),
}
file_path = os.path.join(settings.STATIC_DIR, "pdf", 'dpi_test123.pdf')
svg_path = os.path.join(settings.STATIC_DIR,"images/svg_img/d3-celestial.svg")
template = loader.get_template(self.template_name)
html_string = template.render(context=context, request=request)
try:
pdfkit.from_string(html_string, file_path,options=options)
except:
print("Error found")
if os.path.exists(file_path):
response = FileResponse(open(file_path, 'rb'), content_type='application/force-download')
return response
return HttpResponse("Something went wrong")