'FPDF' object has no attribute 'write_html'
时间: 2023-09-19 19:12:16 浏览: 35
The error message " 'FPDF' object has no attribute 'write_html' " means that the FPDF module you are using does not have a method called `write_html`. This can happen if you are using an outdated version of FPDF or if you are trying to call a method that does not exist in the module.
The `write_html` method is not a built-in method of FPDF. It is a method that is added by some third-party modules that extend the functionality of FPDF. If you want to use the `write_html` method, you need to install the appropriate module that provides this method.
One popular module that adds the `write_html` method to FPDF is called HTML2FPDF. You can install it using pip:
```
pip install html2fpdf
```
Once you have installed the module, you can import it and use the `write_html` method like this:
```python
from fpdf import FPDF
from html2fpdf import HTML2PDF
pdf = FPDF()
html = '<h1>Hello World!</h1>'
pdf.add_page()
HTML2PDF().write_html(pdf, html)
pdf.output('test.pdf', 'F')
```
This will create a PDF file with the text "Hello World!" in a large font.