Thursday, May 11, 2023

Re: PDF generation with xhtml2Pdf in Django

How???

On Thu, 11 May 2023, 14:25 Vishesh Mangla, <manglavishesh64@gmail.com> wrote:
Try weasyprint 

On Thu, 11 May, 2023, 18:38 Oduwa Imade, <oduwa2013@gmail.com> wrote:
Hello Guys! I am trying to generate a Pdf doc(reading data from a database) on Django with xhtml2pdf library. but i encounter this error when i hit the 'Create PDF' button: 

ValueError at /RecruitmentApp/createcvpdf
<PmlTable@0x1B92DB31D50 23 rows x 3 cols> with cell(0,0) containing
'<PmlKeepInFrame at 0x1b92db92e90> size=x' data error - 23 rows in data but 22 row heights .
 ......am not sure what the error is saying or what am doing wrong. Can anyone assist please with ideas on how to tackle this issue?

This is the method in the views.py that handles the pdf creation:

def createPdf(requst):
          #jobseekerID = request.session['rec_ID']
          jobseekerID = 2
         
          cv = CV.objects.select_related('f_key_REC').get(f_key_REC = jobseekerID)
          skill = Skill.objects.select_related('fk_sCV').get(fk_sCV = cv.id)
          qualification = Qualification.objects.select_related('fk_qCV').get(fk_qCV=cv.id)
          certification = Certification.objects.select_related('fk_cCV').get(fk_cCV = cv.id)
          experience = Experience.objects.select_related('fk_eCV').filter(fk_eCV = cv.id)

          template_path = 'Recruitment_App/createpdf_cv.html'
          context = {
               "cv": cv,
               "skills" : skill,
               "qualifications": qualification,
               "certification": certification,
               "experience": experience
          }
          print (cv)
          print(skill)
          print(experience)
          response = HttpResponse(content_type='application/pdf')
          response['Content-Disposition'] = 'filename="cv001.pdf"'
          template = get_template(template_path)
          html = template.render(context)

          pisa_status = pisa.CreatePDF(html, dest=response)
          print(template)
          if pisa_status.err:
               return HttpResponse('We had some errors <pre>' + html + '</pre>')
          return response
         

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/42a1e5d3-718b-4a09-8dbd-b035756765c9n%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CACaE8x6rJ6ie3dAZPaJYcaJLn7P1Mu%3D7Q%2B6eWxvo%3D6KuSCAxEw%40mail.gmail.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CACM0XWxFOpkjaLF75ROU3bqgYP6B3B4WxNc%2BK_RAe-uN0zNCJw%40mail.gmail.com.

No comments:

Post a Comment