pythonpyfpdf

fpdf setting thickness of a line


According to what the fpdf author says, the method for setting the thickness of a line is as follows:

SetLineWidth
       SetLineWidth(float width)
Description
       Defines the line width. By default, the value equals 0.2 mm. The method can be called before the first page is created and the value is retained from page to page.
Parameters
       width
          The width.

My code

pdf = FPDF('W', 'mm', 'A4')
pdf.alias_nb_pages()
pdf.SetLineWidth(0.1)

and the error I get:

Exception has occurred: AttributeError
'FPDF' object has no attribute 'SetLineWidth'

After some tests I understood that pyfpdf does not accept this method so... is there another method to vary the thickness of the lines? In my case they would be the borders of a cell

pdf.cell(6, jump, item, 'LTB', 0, 'C')

Solution

  • Use method set_line_width() of the Python library PyFPDF

    The only error in the code is the name of the method of the class FPDF used to set the thickness of the line drawn in the pdf file.
    The correct method name is set_line_width(), so your code must be correct as shown by the following snippet of code:

    pdf = FPDF('W', 'mm', 'A4')
    pdf.alias_nb_pages()
    #pdf.SetLineWidth(0.1)  # this was for PHP
    pdf.set_line_width(0.1)
    

    Useful documentation links

    The Python method set_line_width() is documented here in the documentation of the version 1.7 of the PyFPDF library.

    PyFPDF is a library for PDF document generation under Python, ported from PHP.

    The OP error present in the code of the question comes from the use of the method SetLineWidth() which is documented in the FPDF 1.51 Reference Manual but this is an old version of the FPDF library written in PHP and not in Python.