pybill.lib.pdfwriters package¶
pybill.lib.pdfwriters package contains the classes and functions used to
produce PDF documents from the PyBill accounting documents.
This package uses reportlab library to build the PDF documents,
specifically the platypus library (see ReportLab documentation
for details).
From this package, the only public class that should be used outside of this
package is the PDFWriter class. This
class can transform any PyBill accounting document into a PDF document. It is
imported and available in the namespace of this package.
Moreover, in this package, we define several reportlab paragraph styles that will be used during the PDF generation.
-
pybill.lib.pdfwriters.style_normal_left¶ Object containing the style for a paragraph aligned on the left.
type:
reportlab.lib.styles.ParagraphStyle
-
pybill.lib.pdfwriters.style_normal_just¶ Object containing the style for a paragraph justified on the left and the right.
type:
reportlab.lib.styles.ParagraphStyle
-
pybill.lib.pdfwriters.style_normal_right¶ Object containing the style for a paragraph aligned on the right.
type:
reportlab.lib.styles.ParagraphStyle
-
pybill.lib.pdfwriters.style_normal_center¶ Object containing the style for a centered paragraph.
type:
reportlab.lib.styles.ParagraphStyle
-
pybill.lib.pdfwriters.style_little_left¶ Object containing the style for a paragraph aligned on the left but with a little font size.
type:
reportlab.lib.styles.ParagraphStyle
-
pybill.lib.pdfwriters.style_little_right¶ Object containing the style for a paragraph aligned on the right but with a little font size.
type:
reportlab.lib.styles.ParagraphStyle
-
pybill.lib.pdfwriters.style_little_center¶ Object containing the style for a centered paragraph but with a little font size.
type:
reportlab.lib.styles.ParagraphStyle
-
pybill.lib.pdfwriters.style_little_indent_left¶ Object containing the style for a paragraph aligned on the left with a little font size and with a positive identation on the first line.
type:
reportlab.lib.styles.ParagraphStyle
Object containing the style for a paragraph of the footer (centered with quite a little font size).
type:
reportlab.lib.styles.ParagraphStyle
-
pybill.lib.pdfwriters.style_title¶ Object containing the style for a paragraph of the title (left aligned with a bigger font size).
type:
reportlab.lib.styles.ParagraphStyle
writers module¶
pybill.lib.pdfwriters.writers module defines the public class that can
generate a PDF file for the accounting documents.
The PDF generation uses the platypus machinery of ReportLab and is, of course, based on PyBill flow generators and templates.
-
class
pybill.lib.pdfwriters.writers.PDFWriter¶ Class writing the PDF for all kinds of accounting documents.
This class uses flow generators that are specific to the kind of accounting document to be rendered in PDF (bill, claim form, debit, downpayment, pro-forma). In order to prevent the instantiation of several generators of the same class, one flow generator of each class is kept in an attribute.
-
flow_generators¶ Attribute containing a dictionary of flow generator objects indexed with the name of the class of the accounting documents they can transform in PDF. This dictionary contains all the specialized flow generators that can be used by this writer.
type: Dictionary of
AbstractFlowGeneratorobjects indexed with unicode keys
-
__init__()¶ Initializes a PDFWriter object and fills the
flow_generatorsattributes with the correct generator objects
-
write(acc_doc, pdf_file)¶ Writes a PDF file for an accounting document.
Parameters: - acc_doc (
GenericAccountingDoc) – Accounting document that must be transformed in PDF. This document contains the configuration object that will be used during this transform (a configuration object contains numerous useful pieces of data). - pdf_file (unicode) – Name of the file where the PDF will be written in.
- acc_doc (
-
utils module¶
pybill.lib.pdfwriters.utils module defines two specific flowable elements
for reportlab.platypus and useful functions.
The flowable elements are the elements that can be inserted in the PDF by the platypus machinery of Reportlab. These specific elements allow the computation of a carry-forward for each page.
-
class
pybill.lib.pdfwriters.utils.NumberParagraph(number, text, style, bulletText=None, frags=None, caseSensitive=1)¶ Bases:
reportlab.platypus.paragraph.ParagraphPyBill-specific paragraph that only contains a number.
The
NumberParagraphobjects will be used by PyBill-specificTotalizableTableclass to compute a sum over the rows of the table, and be able to compute a carry-forward at the end of each page.Basically a
NumberParagraphis identical to a platypusParagraphbut contains a float number (seenumberattribute). This number will be used to compute the sum in aTotalizableTable.-
number¶ Attribute containing the number displayed in the paragraph. It is this number that will be totalized in the
TotalizableTable.type:
float
-
__init__(number, text, style, bulletText=None, frags=None, caseSensitive=1)¶ Initializes a
NumberParagraph.Most of the parameters are identical to those of the platypus
Paragraphinitializer (see this base class for details on the parameters).Parameters: - number (
float) –The number contained in the paragraph. This number will be used by the
TotalizableTableto compute the total over its rows.This parameter is specific to the
NumberParagraphclass. - text (
unicode) – The text contained in the paragraph (seeParagraphfor a full description of the available markup). - style (
reportlab.lib.styles.ParagraphStyle) – The style of the paragraph.
- number (
-
-
class
pybill.lib.pdfwriters.utils.TotalizableTable(data, colWidths=None, rowHeights=None, style=None, repeatRows=0, repeatCols=0, splitByRow=1, emptyTableAction=None, ident=None, hAlign=None, vAlign=None, normalizedData=0, cellStyles=None, rowSplitRange=None, spaceBefore=None, spaceAfter=None, longTableOptimize=None)¶ Bases:
reportlab.platypus.tables.TablePyBill-specific table that can compute a total over its cells.
The total is computed by summing all the the
NumberParagraphobjects contained in the table cells.Usually there is only one
NumberParagraphper row and thus theTotalizableTablecan compute the sum of an amount over the rows.Please note that only the cells of the table that contain a single
NumberParagraphobject will be taken into account for computing the sum.-
_splitRows(availHeight)¶ Splits the table into two tables. The first table height is maximal but less than availHeight.
Parameters: availHeight ( float) – Available height in the PDF frame.Returns: A list of TotalizableTableobjects containing all the rows of the table that have been split into several objects. This list can be empty, have a single element or have several elements.Return type: list of TotalizableTable
-
compute_total()¶ Computes the sum, over the cells of the table, of all the numbers contained in
NumberParagraphobjects.Usually there is only one
NumberParagraphper row, thus thecompute_totalmethod returns the sum over the rows of the table.Please note that only the cells of the table that contain a single
NumberParagraphobject will be taken into account for computing the sum.Returns: the sum of all the numbers contained in the NumberParagraphobjetcs inside the cells of the table.Return type: float
-
The functions define in this module concern the rendering of texts and numbers, and the conversion to the specific flowable elements defined above.
-
pybill.lib.pdfwriters.utils.escape_text(text, normalize_spaces=False)¶ Escapes the text to be written in the PDF document.
This function must be called when the text is in a platypus
Paragraphas some characters must be escaped (e.g. & and <).Warning
Do not call this function after the text has been tagged as the tags will be escaped (e.g.
<b>hello</b>will be turned in<b>Hello</b>).Parameters: - text (
unicode) – Text to be escaped. - normalize_spaces (
bool) – When set toTrue, the function normalizes the whitespace characters (no space at begining and end, only one space between the words).
Returns: The normalized text.
Return type: unicode- text (
-
pybill.lib.pdfwriters.utils.format_number(number, digits=2, separators=None)¶ Formats a number to be written in the PDF document.
This function uses separators defined in the
separatorsdictionnary (separating characters between the sign and the number, between the thousands and between the integer and the digits).Parameters: - number (
float) – Float number to be formatted. - digits (
int) – Number of digits to be displayed (the float number is rounded if it has more digits). - separators (dictionary of
unicodeindexed withunicodekeys) –Dictionary containing the separators used to format a number. There are three separators:
- sign that is inserted between the sign and the non-signed number,
- thousands that is inserted between the thousands and the hundreds, between the millions and the hundreds of thousands, and so on,
- digits that is inserted between the integer and the digits.
When not specified, default separators are used. They are:
{u'sign': u'', u'thousands': u'',\ u'digits': u'.'}.
Returns: The float number formatted in a string.
Return type: unicode- number (
-
pybill.lib.pdfwriters.utils.turn_Table_in_TotalizableTable(table)¶ Builds a PyBill-specific
TotalizableTableobject from a platypus standardTableobject.The two objects have the same internal content.
Parameters: table ( reportlab.platypus.Table) – Platypus table object to be turned in a PyBill-specificTotalizableTableobject.Returns: Pybill-specific TotalizableTableobject identical to the Platypus table.Return type: TotalizableTable
flowgenerators sub-package¶
pybill.lib.pdfwriters.flowgenerators sub-package contains the definition of
the flow generation classes used in the PDF generation with ReportLab
platypus.
These classes generate the flow content of a bill, a claim form, a downpayment,
a pro-forma or a debit: title, various paragraphes, main table detailling the
items, and total table. This flow content will be displayed on various pages by
the AccDocDocumentTemplate`
document template thanks to the platypus machinery.
The sub-package is divided in several modules, each defining one of the flow generator.
abstract module¶
pybill.lib.pdfwriters.flowgenerators.abstract module defines the abstract
base class used by all the PyBill-specific flow generators.
-
class
pybill.lib.pdfwriters.flowgenerators.abstract.AbstractFlowGenerator¶ Abstract class containing the common parts for generating the PDF flow content for the various kinds of accounting documents (bill, claim form, downpayment, debit, pro-forma). Specific parts are generated in the derived classes (one for each kind of document) (cf. Template design pattern).
For a correct behaviour, you must use a flow generator corresponding to the kind of accounting document you want to render in PDF.
The PDF flow content is a list of
reportlab.platypus.Flowableobjects that will be displayed on various pages by the document template and the platypus machinery.-
__init__()¶ Initializes the flow generator.
This constructor should never be called directly as this class is abstract.
-
generate_flow(acc_doc)¶ Generates the flow content (a list of
Flowable) for the accounting document.Parameters: acc_doc ( GenericAccountingDoc) – The current accounting document that must be exported in PDF.Returns: A list of flowable objects to be displayed by the PDF document template. Return type: list of reportlab.platypus.Flowable
-
_get_acc_doc_title(acc_doc)¶ Gives the title of the accounting document.
The title depends on the kind of document. This abstract method will be defined in the children classes.
Parameters: acc_doc ( GenericAccountingDoc) – The current accounting document that must be exported in PDF.Returns: The accounting document title. Return type: unicode
-
_get_items_table(acc_doc)¶ Gives the main table of the accounting document that details the items.
The table can be a 5 columns table (quantity, description, vat rate, tax free unit price, tax free price) or a 4 columns table (quantity, description, tax free unit price, tax free price).
The table is a
TotalizableTableinstead of a classicreportlab.platypus.Tablebecause we need this specific table to compute the carry forwards in theAccDocDocumentTemplatedocument template. Inside this specific table, in each row, we insert oneNumberParagraphthat contains the total of the row. This allows us to know what to add in the carry forward.Parameters: acc_doc ( GenericAccountingDoc) – The current accounting document that must be exported in PDF.Returns: The table detailling the items. This table is a TotalizableTableto allow the computation of the carry forwards in the document template. The items table have 4 columns when the accounting document has no VAT rate and 5 columns when at least one item of the accounting document has a VAT rate.Return type: TotalizableTable
-
_get_bottom_left_element(acc_doc)¶ Gives the element that must be displayed at the bottom left of the accounting document.
This element depends on the kind of document, but is actually a payment terms table. This method can be redefined in the children classes.
Parameters: acc_doc ( GenericAccountingDoc) – The current accounting document that must be exported in PDF.Returns: A flowable object contaning the content to be displayed in the bottom left of the PDF document. Return type: reportlab.platypus.Flowable
-
_get_total_table(acc_doc)¶ Gives the total table of the accounting document (this table appears at the bottom right of the PDF document).
The content of this table depends on the kind of document.
This method relies on the
_get_total_table_cell_contents()that gives the contents of the cells of this table. This method builds aTableobject with these contents.Parameters: acc_doc ( GenericAccountingDoc) – The current accounting document that must be exported in PDF.Returns: The total table. This table embeds its style and is ready to be inserted in the flow. Return type: reportlab.platypus.Table
-
_get_total_table_cell_contents(acc_doc)¶ Gives the contents of the cells of the total table.
These contents will be used by the
_get_total_table()method to build the total table. The cell contents depend on the kind of accounting document currently processed.The contents of the cells are given as a list of triples: name, number and style. Each couple corresponds to one row of the total table.
- The name is a list of unicode strings corresponding to several lines describing the content of the row. It is written in the first cell of the row. The first line is written with the regular font, the next are written with littler font.
- The number is a float corresponding to the amount of the row. It is written in the second cell of the row.
- The style is a specification of how the row must be displayed. It can contain u”bold”, u”italic”, both or none of them.
Please note that the name will be escaped when inserted in the table. Therefore it should not contain any tag of style. You should use the style element in the triple to specify the style of the row.
This method is abstract and will be implemented in the child classes.
Parameters: acc_doc ( GenericAccountingDoc) – The current accounting document that must be exported in PDF.Returns: A list describing the cells of the total table. The first element is a list of unicode strings corresponding to the various lines of the name of the row; the second element is a float corresponding to the number written in the row; the third element is a specification of the style of the row ( u"bold",u"italic",u"bold italic",u"").Return type: list of triples (list of unicode,float,unicode)
-
_build_cell_contents_for_totals(acc_doc)¶ Builds the cell contents corresponding to the first rows of the total table.
These rows describe the totals (tax free total, vat amounts, including taxes total, holdbacks). As they are inserted in the total tables generated by all the subclasses, they have been factorized here.
See
_get_total_table_cell_contents()method for a description of the triples describing the cell contents in the total table.This method generates different rows if the accounting document contain or doesn’t contain VAT rates, contain or doesn’t contain holdbacks. If it has got VAT rates, the totals rows will be: tax free total, various VAT amounts, including taxes total. If it hasn’t got VAT rates, the totals rows will be: total. If it has holdbacks, two or three more rows will be added: holdbacks on tax free amounts and holdbacks on VAT amounts (if the holdbacks are on VAT) and holdbacks to be paid.
Returns: A list describing the first cells of the total table, corresponding to the totals. The first element is a list of unicode strings corresponding to the various lines of the name of the row; the second element is a float corresponding to the number written in the row; the third element is a specification of the style of the row ( u"bold",u"italic",u"bold italic",u"").Return type: list of triples (list of :class:unicode`, float,unicode)
-
bill_generator module¶
pybill.lib.pdfwriters.flowgenerators.bill_generator module defines the flow
generator for the bill entities.
The flow generator generates the title, various paragraphes, the main table
detailling the items, and the total table. This flow content will be displayed
on various pages by the
AccDocDocumentTemplate
document template with the platypus machinery.
-
class
pybill.lib.pdfwriters.flowgenerators.bill_generator.BillFlowGenerator¶ Bases:
pybill.lib.pdfwriters.flowgenerators.abstract.AbstractFlowGeneratorClass generating the PDF flow content for a
Bill.-
_get_acc_doc_title(acc_doc)¶ Gives the title of the accounting document (here, a bill).
Parameters: acc_doc ( GenericAccountingDoc) – The current accounting document that must be exported in PDF.Returns: The accounting document title. Return type: unicode
-
_get_total_table_cell_contents(acc_doc)¶ Gives the contents of the cells of the total table.
These contents will be used by the
_get_total_tablemethod to build the total table.Parameters: acc_doc ( GenericAccountingDoc) – The current accounting document that must be exported in PDF (here a bill).Returns: A list describing the cells of the total table. The first element is a list of unicode strings corresponding to the various lines of the name of the row; the second element is a float corresponding to the number written in the row; the third element is a specification of the style of the row ( u"bold",u"italic",u"bold italic",u"").Return type: list of triples (list of unicode,float,unicode)
-
claimform_generator module¶
pybill.lib.pdfwriters.flowgenerators.bill_generator module defines the flow
generator for the claim form entities.
The flow generator generates the title, various paragraphes, the main table
detailling the items, and the total table. This flow content will be displayed
on various pages by the
AccDocDocumentTemplate
document template with the platypus machinery.
-
class
pybill.lib.pdfwriters.flowgenerators.claimform_generator.ClaimFormFlowGenerator¶ Bases:
pybill.lib.pdfwriters.flowgenerators.abstract.AbstractFlowGeneratorClass generating the PDF flow content for a
ClaimForm.-
_get_acc_doc_title(acc_doc)¶ Gives the title of the accounting document (here, a claim form).
Parameters: acc_doc ( GenericAccountingDoc) – The current accounting document that must be exported in PDF.Returns: The accounting document title. Return type: unicode
-
_get_total_table_cell_contents(acc_doc)¶ Gives the contents of the cells of the total table.
These contents will be used by the
_get_total_tablemethod to build the total table.Parameters: acc_doc ( GenericAccountingDoc) – The current accounting document that must be exported in PDF (here a claim form).Returns: A list describing the cells of the total table. The first element is a list of unicode strings corresponding to the various lines of the name of the row; the second element is a float corresponding to the number written in the row; the third element is a specification of the style of the row ( u"bold",u"italic",u"bold italic",u"").Return type: list of triples (list of unicode,float,unicode)
-
debit_generator module¶
pybill.lib.pdfwriters.flowgenerators.debit_generator module defines the flow
generator for the debit entities.
The flow generator generates the title, various paragraphes, the main table
detailling the items, and the total table. This flow content will be displayed
on various pages by the
AccDocDocumentTemplate
document template with the platypus machinery.
-
class
pybill.lib.pdfwriters.flowgenerators.debit_generator.DebitFlowGenerator¶ Bases:
pybill.lib.pdfwriters.flowgenerators.abstract.AbstractFlowGeneratorClass generating the PDF flow content for a
Debit.-
_get_acc_doc_title(acc_doc)¶ Gives the title of the accounting document (here, a debit).
Parameters: acc_doc ( GenericAccountingDoc) – The current accounting document that must be exported in PDF.Returns: The accounting document title. Return type: unicode
-
_get_bottom_left_element(acc_doc)¶ Gives the element that must be displayed at the bottom left of the accounting document.
In the case of a debit, this element is nothing.
Parameters: acc_doc ( GenericAccountingDoc) – The current accounting document that must be exported in PDF (here, a debit).Returns: An empty table to be displayed in the bottom left of the PDF document. Return type: reportab.platypus.Flowable
-
_get_total_table_cell_contents(acc_doc)¶ Gives the contents of the cells of the total table.
These contents will be used by the
_get_total_tablemethod to build the total table.Parameters: acc_doc ( GenericAccountingDoc) – The current accounting document that must be exported in PDF (here a debit).Returns: A list describing the cells of the total table. The first element is a list of unicode strings corresponding to the various lines of the name of the row; the second element is a float corresponding to the number written in the row; the third element is a specification of the style of the row ( u"bold",u"italic",u"bold italic",u"").Return type: list of triples (list of unicode,float,unicode)
-
downpayment_generator module¶
pybill.lib.pdfwriters.flowgenerators.downpayment_generator module defines
the flow generator for the downpayment entities.
The flow generator generates the title, various paragraphes, the main table
detailling the items, and the total table. This flow content will be displayed
on various pages by the
AccDocDocumentTemplate
document template with the platypus machinery.
-
class
pybill.lib.pdfwriters.flowgenerators.downpayment_generator.DownpaymentFlowGenerator¶ Bases:
pybill.lib.pdfwriters.flowgenerators.abstract.AbstractFlowGeneratorClass generating the PDF flow content for a
Downpayment.-
_get_acc_doc_title(acc_doc)¶ Gives the title of the accounting document (here, a downpayment).
Parameters: acc_doc ( GenericAccountingDoc) – The current accounting document that must be exported in PDF.Returns: The accounting document title. Return type: unicode
-
_get_total_table_cell_contents(acc_doc)¶ Gives the contents of the cells of the total table.
These contents will be used by the
_get_total_tablemethod to build the total table.Parameters: acc_doc ( GenericAccountingDoc) – The current accounting document that must be exported in PDF (here a downpayment).Returns: A list describing the cells of the total table. The first element is a list of unicode strings corresponding to the various lines of the name of the row; the second element is a float corresponding to the number written in the row; the third element is a specification of the style of the row ( u"bold",u"italic",u"bold italic",u"").Return type: list of triples (list of unicode,float,unicode)
-
proforma_generator module¶
pybill.lib.pdfwriters.flowgenerators.proforma_generator module defines the
flow generator for the pro-forma entities.
The flow generator generates the title, various paragraphes, the main table
detailling the items, and the total table. This flow content will be displayed
on various pages by the
AccDocDocumentTemplate
document template with the platypus machinery.
-
class
pybill.lib.pdfwriters.flowgenerators.proforma_generator.ProFormaFlowGenerator¶ Bases:
pybill.lib.pdfwriters.flowgenerators.abstract.AbstractFlowGeneratorClass generating the PDF flow content for a
ProForma.-
_get_acc_doc_title(acc_doc)¶ Gives the title of the accounting document (here, a pro-forma).
Parameters: acc_doc ( GenericAccountingDoc) – The current accounting document that must be exported in PDF.Returns: The accounting document title. Return type: unicode
-
_get_bottom_left_element(acc_doc)¶ Gives the element that must be displayed at the bottom left of the accounting document.
In the case of a pro-forma, this element is a set of lines asking for the agreement of the receiver.
Parameters: acc_doc ( GenericAccountingDoc) – The current accounting document that must be exported in PDF (here, a pro-forma).Returns: A table with a single cell containing the agreement lines read from the configuration. This table is to be displayed in the bottom left of the PDF document. Return type: reportlab.platypus.Flowable
-
_get_total_table_cell_contents(acc_doc)¶ Gives the contents of the cells of the total table.
These contents will be used by the
_get_total_tablemethod to build the total table.Parameters: acc_doc ( GenericAccountingDoc) – The current accounting document that must be exported in PDF (here a pro-forma).Returns: A list describing the cells of the total table. The first element is a list of unicode strings corresponding to the various lines of the name of the row; the second element is a float corresponding to the number written in the row; the third element is a specification of the style of the row ( u"bold",u"italic",u"bold italic",u"").Return type: list of triples (list of unicode,float,unicode)
-
templates sub-package¶
pybill.lib.pdfwriters.templates sub-package contains the definition of the
template classes (page templates and document template) used in the PDF
generation with ReportLab platypus.
The page templates describe the structure of the PDF pages and where the flow
content can be written. The document template describes a PDF document, mainly
explaining which page templates will be used. Both templates are used by the
platypus machinery to display, into the PDF documents, the flowables generated
by the pybill.lib.pdfwriters.flowables flow generators.
The sub-package is divided in several modules, each defining one type of template.
page_templates module¶
pybill.lib.pdfwriters.templates.page_templates module contains the
definition of the page template classes used in the PDF generation with
ReportLab platypus.
These classes are derived from platypus standard classes but are specific to PyBill software. The page templates draw the static content specific to the accounting documents.
-
class
pybill.lib.pdfwriters.templates.page_templates.AccDocPageTemplate(acc_doc, template_id='')¶ Bases:
reportlab.platypus.doctemplate.PageTemplateClass defining the page template used to draw the other pages of accounting PDF documents (not the first one).
This page template has a main frame that will be filled with the accounting table, and various other frames containing the logo, and the footer that are displayed identically on each page (static content).
This page template can only be used with a document created from the
AccDocDocumentTemplatedocument template. It contains some methods for writing the carry forward computed in this document template.-
acc_doc¶ Attribute containing the accounting entity thate describes the actual document to be rendered in PDF.
type:
GenericAccountingDoc
-
__init__(acc_doc, template_id='')¶ Initializes an
AccDocPageTemplateobject.Parameters: - acc_doc (
GenericAccountingDoc) – Accounting entity containing the actual document to be rendered in PDF. - template_id (
str) – identifier (name) of the page template.
- acc_doc (
-
_create_main_frame()¶ Creates the main frame of the page template, in which the flow, generated from the accounting entity, will be displayed.
Returns: The frame in which the PDF flow will be rendered. Return type: reportlab.platypus.Frame
-
beforeDrawPage(canvas, document)¶ Overrides the method called before drawing a new page of the PDF document.
This method draws various static data on the page (logo, company address, footer, page number, carry forward from previous page).
Parameters: - canvas (
reportlab.pdfgen.canvas.Canvas) – Canvas of the page where the content can be written. - document (
AccDocDocumentTemplate) – PDF Document created from a template. This document contains various useful information such as the page number or the carry forward.
- canvas (
-
afterDrawPage(canvas, document)¶ Overrides the method called after drawing a page of the PDF document.
This method draws the carry forward to be brought forward to the next page.
Parameters: - canvas (
reportlab.pdfgen.canvas.Canvas) – Canvas of the page where content can be written. - canvas – Canvas of the page where the content can be written.
- document (
AccDocDocumentTemplate) – PDF Document created from a template. This document contains various useful information such as the page number or the carry forward.
- canvas (
-
_draw_static_content(canvas, document)¶ Draws on the PDF page the static content that is displayed on all pages, i.e. logo, company address, footer, page number.
Parameters: - canvas (
reportlab.pdfgen.canvas.Canvas) – Canvas of the page where the content can be written. - document (
AccDocDocumentTemplate) – PDF Document created from a template. This document contains various useful information such as the page number.
- canvas (
-
_draw_top_carry_forward(canvas, document)¶ Draws on the PDF page the carry forward that is brought forward from the previous page.
This carry forward is displayed at the top of the page just before the main frame.
Parameters: - canvas (
reportlab.pdfgen.canvas.Canvas) – Canvas of the page where the content can be written. - document (
AccDocDocumentTemplate) – PDF Document created from a template. This document contains various useful information such as the carry forward.
- canvas (
-
_draw_bottom_carry_forward(canvas, document)¶ Draws on the PDF page the carry forward that is brought forward to the next page.
This carry forward is displayed at the bottom of the page just after the main frame.
Parameters: - canvas (
reportlab.pdfgen.canvas.Canvas) – Canvas of the page where the content can be written. - document (
AccDocDocumentTemplate) – PDF Document created from a template. This document contains various useful information such as the page number.
- canvas (
-
-
class
pybill.lib.pdfwriters.templates.page_templates.AccDocFirstPageTemplate(acc_doc, template_id='')¶ Bases:
pybill.lib.pdfwriters.templates.page_templates.AccDocPageTemplateClass defining the page template used to draw the first pages of accounting documents in PDF.
This page template has a main frame that will be filled with the accounting table, and various other frames containing the logo, the date, the address, the footer that are displayed identically on each page (static content).
This template is a specialization of
AccDocPageTemplate.This page template can only be used with a document created from the
AccDocDocumentTemplatedocument template. It contains some methods for writing the carry forward computed in this document template.-
__init__(acc_doc, template_id='')¶ Initializes an
AccDocFirstPageTemplateobject.Parameters: - acc_doc (
GenericAccountingDoc) – Accounting entity containing the actual document to be rendered in PDF. - template_id (
str) – identifier (name) of the page template.
- acc_doc (
-
_create_main_frame()¶ Creates the main frame of the page template, in which the flow, generated from the accounting entity, will be displayed.
The main frame on the first page is littler than on the other pages as there is more static content on the first page (addresses, etc.)
Returns: The frame in which the PDF flow will be rendered. Return type: reportlab.platypus.Frame
-
beforeDrawPage(canvas, document)¶ Overrides the method called before drawing a new page of the PDF document.
This method draws various static data on the page (logo, company address, footer, page number, carry forward from previous page).
Parameters: - canvas (
reportlab.pdfgen.canvas.Canvas) – Canvas of the page where the content can be written. - document (
AccDocDocumentTemplate) – PDF Document created from a template. This document contains various useful information such as the page number.
- canvas (
-
_draw_specific_static_content(canvas, document)¶ Draws on the PDF page some specific static content that is displayed on each page based on this template (in fact, only the first page).
This specific static content is document metadata, receiver address, and date.
Parameters: - canvas (
reportlab.pdfgen.canvas.Canvas) – Canvas of the page where the content can be written. - document (
AccDocDocumentTemplate) – PDF Document created from a template. This document contains various useful information such as the page number.
- canvas (
-
doc_templates module¶
pybill.lib.pdfwriters.templates.doc_templates contains the definition of
the document template classes used in the PDF generation with ReportLab
platypus.
These classes are derived from platypus standard classes but are specific to
PyBill software. The document template is used to create new PDF
documents for the PyBill accounting documents. It adds some behaviour to its
base class in the flow content management, specifically the ability to compute
the carry forward from a TotalizableTable
inserted in the flow content.
-
class
pybill.lib.pdfwriters.templates.doc_templates.AccDocDocumentTemplate(filename, acc_doc)¶ Bases:
reportlab.platypus.doctemplate.BaseDocTemplateThe accounting document template is a class explaining how to create an accouting PDF document.
It uses the
AccDocPageTemplateand theAccDocFirstPageTemplatepage templates and can compute the carry forward that has to be brought forward from one page to another.The computation of the carry forward is only possible if the main table of the document is a
TotalizableTableand if, in this table, the total of each row is put in aNumberParagraph.The carry forward will not appear if a
TotalizableTableis not used.-
carry_forward¶ Attribute containing the carry forward that has to be brought forward from a finished page to the next page.
type:
float
-
_carry_forward_computed¶ Attribute containing a flag set to
Trueif the carry forward has once been computed.type:
bool
-
display_carry_forward¶ Attribute containing a flag set to
Trueif the carry forward has to be displayed at end of the page (and the beginning of the next page).type:
bool
-
all_flowables_handled¶ Attribute containing a flag set to
Trueif all the flowables have been handled.The carry forward must not be displayed on the last page. The only way I found to know if is the last page, is to watch the build progress and set a flag when I see the last flowable has been handled. Anyway, this works properly because the last flowable of the document is in a
KeepTogetherand is never splitted over pages.type:
bool
-
_estim_num_of_flowables¶ Attribute containing the estimated number of flowables to handle (see
all_flowables_handledfor more details).type:
int
-
__init__(filename, acc_doc)¶ Initializes an
AccDocDocumentTemplateobject.This method initializes the correct page templates to be used when generating the document, sets the PDF document metadata, and initializes the attributes.
Parameters: - filename (unicode) – name of the PDF output file
- acc_doc (
GenericAccountingDoc) – Accounting entity containing the actual document to be rendered in PDF.
-
afterFlowable(flow)¶ Overrides base method to compute the carry forward if the flowable is a
TotalizableTable.The only
TotalizableTablein the flowables list is the main table that will be used to compute the carry forward.Parameters: flow ( reportlab.platypus.Flowable) – Flowable that has just been drawn on the page.
-
handle_pageBegin()¶ Overrides base method to add a change of page template after the first page and to unset the
display_carry_forwardflag.
-
handle_pageEnd()¶ Overrides base method to set the
display_carry_forwardflag when we are ending a page (that is not the last page) and when the main table has already been displayed (or is being displayed).
-
watch_flowable_handling(ev_type, value)¶ Progress function that is called by the document template as it builds the PDF document.
This function has been registered by the :meth`__init__` method in the hook called during document process (cf.
_onProgressattribute of the base class). It sets theall_flowables_handledflag.Parameters: - ev_type (
str) –Type of the event. Possible types are:
PASS: number of the pass starting now. Numerous passes are done when working with multi-build for indexing flowables.STARTED: starting build.SIZE_EST: estimated number of flowables to be handled (some flowables may be added when one flowable is splitted over pages).PROGRESS: number of the flowable that has just been handled (if a flowable is splitted over pages, its number will appear various times in PROGRESS).PAGE: number of the page that has just been finished.FINISHED: ending build.
- value (
int) – Number related to the event.
- ev_type (
-