xhtml2pdf: black square box while generating pdf (unicode error)
A weird problem. While generating pdf, inplace of unicodes square black boxes apperars. Dont know if its unicode or font-face error. I even dont know if to use the “font-face and font-family” to generate the unicode into pdf. Anything I am missing ?? Great thanks.
Code snippet # -- coding: utf-8 --
from xhtml2pdf import pisa
from StringIO import StringIO
source = """<html>
            <style>
                @font-face {
                font-family: Mangal;
                src: url("mangal.ttf");
                }
                body {
                font-family: Mangal;
                }
            </style>
            <body>
                This is a test <br/>
                       सरल
            </body>
        </html>"""
# Utility function
def convertHtmlToPdf(source):       
    pdf = StringIO()
    pisaStatus = pisa.CreatePDF(StringIO(source.encode('utf-8')), pdf)
    # return True on success and False on errors
    print "Success: ", pisaStatus.err
    return pdf
# Main program
if __name__=="__main__":
    print pisa.showLogging()
    pdf = convertHtmlToPdf(source)
    fd = open("test.pdf", "w+b")
    fd.write(pdf.getvalue())
    fd.close()
About this issue
- Original URL
 - State: closed
 - Created 11 years ago
 - Comments: 31 (2 by maintainers)
 
yes it’s work but if you put some russian chars, it creates black squares the problem is how we can use non english chars?
It’s very disappoiting to add local fonts for any HTML document to render in non-latin encoding