Answer the question
In order to leave comments, you need to log in
How to give an html page and then convert it to PDF?
Hello.
What I do:
1) Parse the pages I need.
2) With this data, I dynamically render an html page.
3) I'm trying to convert an html page to pdf and give it to users.
I'm trying to do just that, the kibo parser receives the html code (not always amenable to normal parsing) and I bring it to an adequate form through css and html.
I'm trying to do something like:
The error is that the PDF convector does not want to accept the rendering of the html page.
def parse(request):
done = csrf(request)
if request.POST: # начало парсера
USERNAME = request.POST.get('logins', '')
PASSWORD = request.POST.get('password', '')
dialogue_url = request.POST.get('links', '')
total_pages = int(request.POST.get('numbers', ''))
news = []
news.extend(parse_one(USERNAME, PASSWORD, dialogue_url, total_pages)) #вызываю функцию парсера
contex = {
"news" : news,
}
done.update(contex) #конец парсера
pageclan = render(request, 'marketing/parser.html', done) # как-то так пытаюсь рендерить страницу и сохранить её в переменную
# create an API client instance #начало pdf форминга
client = pdfcrowd.Client("username", "key")
# convert a web page and store the generated PDF to a variable
pdf = client.convertURI(pageclan)
# set HTTP response headers
response = HttpResponse(content_type="application/pdf")
response["Cache-Control"] = "max-age=0"
response["Accept-Ranges"] = "none"
response["Content-Disposition"] = "attachment; filename=jivo_log.pdf"
# send the generated PDF
response.write(pdf)
return response
Answer the question
In order to leave comments, you need to log in
pageclan contains an HttpResponse object, and convertURI takes a page reference. Need something like
tmpl = get_template('marketing/parser.html')
html = tmpl.render(done)
pdf = client.convertHtml(html)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question