Using Wkhtmltopdf and pdkit but copy text option not working once the PDF is generated

74 views Asked by At

I am using Wkhtmltopdf pdfkit with python but when the pdf is generated not able to copy the text once the pdf is generated on ubuntu.. Working fine on windows

options I am using with options -

Code I am using to generate the PDF. Below is the code I am using to generate the PDF

def generatePurchaseOrderPdf(datas,file_name,file_path,template_name, Quote, quote_vendor, ModelClass):
    options={
            'no-outline':None,
            'page-size': 'A4',
            'margin-top': '0.2in',
            'margin-bottom': '0.55in',
            'margin-right': '0.1in',
            'margin-left': '0.1in',
            'encoding': "utf-8",
            'footer-font-size': "8",
            'footer-spacing':8,
            'header-font-size':"8",
            'footer-right': "Page [page] of [topage]",
            'footer-center':"Madoverbuildings AI Private Ltd.",
            'footer-font-size': "7",
            'footer-spacing':5,
            'custom-header': [
                ('Accept-Encoding', 'gzip')
            ],
            'no-outline': None
        }

    try:
        path_wkhtmltopdf = r'C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe'
        template = get_template(f"{template_name}.html")
        context = template.render(datas)
        exact_file_path = f'{settings.BASE_DIR}/{file_path}/{file_name}.pdf'
        if ENV == "LOCAL":
            config = pdfkit.configuration(wkhtmltopdf=path_wkhtmltopdf)
            pdfkit.from_string(
                context,exact_file_path ,   
                options= options,
                configuration=config            
            )
        else:
            pdfkit.from_string(
                context,exact_file_path ,   
                options= options  
            )
        return exact_file_path
    except Exception as e:
        exc_type, exc_obj, exc_tb = sys.exc_info()
        fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
        print(e)
        print(exc_type, fname, exc_tb.tb_lineno)
        logger.warning(f'generatePurchaseOrderPdf errors {e, exc_type, fname, exc_tb.tb_lineno} - {datetime.datetime.now()} ')


1

There are 1 answers

6
R.Dereu On

Hard to reply without seeing the actual code. First thing to check is make sure that your Windows and Ubuntu run the same version of python as well as Wkhtmltopdf.

when the pdf is generated not able to copy the text once the pdf is generated on ubuntu

What do you mean by copy the text? Do you want to use it in a variable? Please provide the relevant parts of your code so we can help you further. Also post any error message you may be getting when running on Ubuntu.