Why does generating a PDF report create an HTML file?
10:41 18 Jan 2023

I am currently learning how to use Odoo. I am doing the following tutorial on PDF report generation.

The instruction is to allow the user to generate a pdf file gathering the offers that have been made for the purchase of a real estate property.

It took me a long time to make the "Print" (on which clicking should generate a .pdf) button usable without getting an error telling me that wkhtmltopdf was not found on my computer.

It works now but I can't open the .pdf generated by Odoo.

Here is what I did on my side to get there

.xml files in Odoo

I work with version 16.

I created a reports folder with two .xml files based on the examples in the tutorial.

report_property_offers.xml



    

event_reports.xml



    
        Report Property Offers
        estate.property
        qweb-pdf
        estate.report_property_offers
        estate.report_property_offers
        'Property Offers - %s' % (object.name or 'Attendee').replace('/','')
        
        report
    

The files are well indicated in the manifest in the data part.

wkhtmltopdf installation

I work on Windows 11.

  • According to this wiki, I have installed version 0.12.5-1
  • I have downloaded the wkhtmltox-0.12.5-1.msvc2015-win64.exe version on this page
  • I added in the PATH of my environment variables the following path: C:\Program Files\wkhtmltopdf\bin
  • The command wkthmltopdf --version in my console gives the following result: wkhtmltopdf 0.12.5 (with patched qt)
  • At that time, the PDF generation was still not working and Odoo told me every time: Unable to find Wkhtmltopdf on this system, I found this video by chance and I added in Odoo in Settings → Technical → System Parameters the following key: webkit_path : C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf
  • When I start my Odoo application, I see the following line in logs: INFO ? odoo.addons.base.models.ir_actions_report: Will use the Wkhtmltopdf binary at C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe

The problem

After all this when I click on the print button, it generates a .pdf file on my computer. The problem is that I can't open the file (with chrome for example).

When I open the .pdf file with VS Code, I see that the data is present... but in HTML format!


        
            
                
                
                Odoo Report
                
....
                    

Big Villa

Expected Price: 1,600,000.0
....

How to make this file generated by Odoo really a PDF and not HTML?

python odoo wkhtmltopdf windows-11