2016-03-23 8 views
0

1) Bilgi almak için bazı sayfaları ayrıştırıyorum. 2) Ayrılması zor bilgi gibi, ben html sayfasına yükleyin ve özel css ile güzelleştirin. 3) Daha sonra müşterilere sunmak için pdf'ye dönüştürmeyi deniyorum.Dinamik html sayfasını django'ya nasıl dönüştürebilirim?

Ancak, tüm pdf-konvektörler belirli url veya dosya vb. Örneğin:

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 
     client = pdfcrowd.Client(*** ***) 

     # convert a web page and store the generated PDF to a variable. That is doesn't work. Convertor doesn't support such url. 
     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 

İyi çalışabilecek araçlar var mı? PDFCrowd Python API documentation itibaren

cevap

0

:

pdf = client.convertHtml("<head></head><body>My HTML Layout</body>")

Size kodunu değiştirmek anlamına gelir:

Ayrıca sadece yerine convertURI() ait convertHtml() yöntemi kullanmak, çiğ HTML kodunu dönüştürebilirsiniz işlenen sayfanızla (bir HTML dizesi) convertHtml yöntemini kullanın:

pdf = client.convertHtml(pageclan.content) 
+0

'HttpResponse' nesne hiçbir özellik 'kodlamak' html = Html.Encode ('utf-8') Evet, sadece 'content' kullanmak gerekir @SergeyBakotin o utf-8 ya da bir şey –

+0

sormak görünüyor vardır . Güncellenmiş cevaba bakınız. – Selcuk