Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with hindi text html encoding into pdf #744

Open
akashsagar8 opened this issue Jan 6, 2024 · 3 comments
Open

Problem with hindi text html encoding into pdf #744

akashsagar8 opened this issue Jan 6, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@akashsagar8
Copy link

akashsagar8 commented Jan 6, 2024

Describe the Bug

I m using xhtml2pdf Version: 0.2.5 with django version 3.2 , I m trying to convert my hindi text into pdf but after converting pdf hindi text is not encoded with a right way , it gives black boxes or unreadable characters ------ I already used in html file meta encoding ="utf-8" line and also attached another libarary for hindi language like devnagriRegular.ttf file but not working

##this is my view function in django

def show_products(request):
products = crudajax.objects.filter(delete_flag=False).all()
template_path = 'pdf_report.html'
context = {'products': products}

response = HttpResponse(content_type='application/pdf')
response['Content-Disposition'] = 'attachment; filename="report.pdf"'

template = get_template(template_path)
html = template.render(context)

result = BytesIO()
# pisa.CreatePDF(
#  template, dest=response,  encoding='UTF-8')
pdf = pisa.pisaDocument(BytesIO(html.encode("UTF-8")), result, encoding='UTF-8')


if not pdf.err:
  return HttpResponse(result.getvalue(), content_type='application/pdf')
if pdf.err:
    return HttpResponse('We had some errors <pre>' + html + '</pre>')

return response

Expected Behavior

I want to convert my hindi text into pdf with a encoded way

Actual Behavior

Actual behavior is , it convert english language only if i give another laguage like hindi , it does not encode.

Additional Information

Traceback

hindi text

hindi text

System Information

I m using acer i5

OS version:Version 10.0.22631 Build 22631

Python version:3.9.5
XHTML2PDF version:Version: 0.2.5

@akashsagar8 akashsagar8 added the bug Something isn't working label Jan 6, 2024
@stefan6419846
Copy link
Contributor

Could you please provide some standalone code without relying on custom Django models and views, ideally without even using Django as this should be irrelevant in this case?

@akashsagar8
Copy link
Author

akashsagar8 commented Jan 9, 2024 via email

@stefan6419846
Copy link
Contributor

Could you please provide the standalone code you apparently have then to simplify reproduction?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants