Package s3 :: Module s3pdf :: Class S3PDF
[frames] | no frames]

Class S3PDF

source code

     object --+    
              |    
s3rest.S3Method --+
                  |
                 S3PDF


Class to help generate PDF documents.

A typical implementation would be as follows:

    exporter = s3base.S3PDF()
    return exporter(xrequest, **attr)

Currently this class supports two types of reports:
A List: Typically called from the icon shown in a search
        For example inv/warehouse
A Header plus List: Typically called from a button on a form
        For example ???

Add additional generic forms to the apply_method() function
For specialist forms a S3PDF() object will need to be created.
See the apply_method() for ideas on how to create a form,
but as a minimum the following structure is required:

    pdf = S3PDF()
    pdf.newDocument(pdf.defaultTitle(resource))

    # Add specific pages here

    return pdf.buildDoc()

Nested Classes
  S3PDFOCRForm
Extended class of the BaseDocTemplate to be used with OCR Forms.
Instance Methods
 
apply_method(self, r, **attr)
Apply CRUD methods
source code
 
dameraulevenshtein(self, seq1, seq2)
Calculate the Damerau-Levenshtein distance between sequences.
source code
 
newDocument(self, title, header, footer, filename=None, heading=None)
This will create a new empty PDF document.
source code
 
newOCRForm(self, formUUID, pdfname="ocrform.pdf", top=65, left=50, bottom=None, right=None, **args) source code
 
OCRPDFManager(self)
Produces OCR Compatible PDF forms
source code
 
setMargins(self, left=None, right=None, top=None, bottom=None)
Method to set the margins of the document
source code
 
setPortrait(self)
Method to set the orientation of the document to be portrait
source code
 
setLandscape(self)
Method to set the orientation of the document to be landscape
source code
 
addTable(self, resource=None, raw_data=None, list_fields=None, report_groupby=None, report_hide_comments=False)
Method to create a table that will be inserted into the document
source code
 
extractrHeader(self, rHeader)
Method to convert the HTML generated for a rHeader into PDF
source code
 
addrHeader(self, resource=None, raw_data=None, list_fields=None, report_hide_comments=False)
Method to create a rHeader table that is inserted into the document
source code
 
addPlainTable(self, text, style=None, append=True) source code
 
addParagraph(self, text, style=None, append=True)
Method to create a paragraph that may be inserted into the document
source code
 
addSpacer(self, height, append=True)
Add a spacer to the story
source code
 
addOverlay(self, callback, data)
Add an overlay to the page
source code
 
addBoxes(self, cnt, append=True)
Add square text boxes for text entry to the story
source code
 
throwPageBreak(self)
Method to force a page break in the report
source code
 
changePageTitle(self, newTitle)
Method to force a page break in the report
source code
 
getStyledTable(self, table, colWidths=None, rowHeights=None, style=[])
Method to create a simple table
source code
 
getTableMeasurements(self, tempTable)
Method to calculate the dimensions of the table
source code
 
cellStyle(self, style, cell)
Add special styles to the text in a cell
source code
 
addCellStyling(self, table, style)
Add special styles to the text in a table
source code
 
setHeaderBanner(self, image)
Method to add a banner to a page used by pageHeader
source code
 
pageHeader(self, canvas, doc)
Method to generate the basic look of a page.
source code
 
pageFooter(self, canvas, doc)
Method to generate the basic look of a page.
source code
 
buildDoc(self)
Method to build the PDF document.
source code

Inherited from s3rest.S3Method: __call__, widget

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __init__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Static Methods
 
defaultTitle(resource)
Method to extract a generic title from the resource using the crud strings
source code

Inherited from s3rest.S3Method: crud_string

Properties

Inherited from object: __class__

Method Details

apply_method(self, r, **attr)

source code 

Apply CRUD methods

@param r: the S3Request
@param attr: dictionary of parameters for the method handler
            The attributes that it knows about are:
          * componentname
          * formname
          * list_fields
          * report_groupby
          * report_hide_comments

@return: output object to send to the view

Parameters:
  • r - the S3Request
  • attr - dictionary of parameters for the method handler
Returns:
output object to send to the view
Overrides: s3rest.S3Method.apply_method

dameraulevenshtein(self, seq1, seq2)

source code 

Calculate the Damerau-Levenshtein distance between sequences.

This distance is the number of additions, deletions, substitutions, and transpositions needed to transform the first sequence into the second. Although generally used with strings, any sequences of comparable objects will work.

Transpositions are exchanges of *consecutive* characters; all other operations are self-explanatory.

This implementation is O(N*M) time and O(M) space, for N and M the lengths of the two sequences.

>>> dameraulevenshtein('ba', 'abc')
2
>>> dameraulevenshtein('fee', 'deed')
2

It works with arbitrary sequences too: >>> dameraulevenshtein('abcd', ['b', 'a', 'c', 'd', 'e']) 2

newDocument(self, title, header, footer, filename=None, heading=None)

source code 

This will create a new empty PDF document. Data then needs to be added to this document.

Parameters:
  • title - The title that will appear at the top of the document and in the filename
Returns:
An empty pdf document

newOCRForm(self, formUUID, pdfname="ocrform.pdf", top=65, left=50, bottom=None, right=None, **args)

source code 

OCRPDFManager(self)

source code 

Produces OCR Compatible PDF forms

defaultTitle(resource)
Static Method

source code 

Method to extract a generic title from the resource using the crud strings

Returns:
the title as a String

setMargins(self, left=None, right=None, top=None, bottom=None)

source code 

Method to set the margins of the document

Parameters:
  • left - the size of the left margin, default None
  • right - the size of the right margin, default None
  • top - the size of the top margin, default None
  • bottom - the size of the bottom margin, default None

    The margin is only changed if a value is provided, otherwise the last value that was set will be used. The original values are set up to be an inch - in newDocument()

To Do: make this for a page rather than the document

setPortrait(self)

source code 

Method to set the orientation of the document to be portrait

To Do: make this for a page rather than the document

setLandscape(self)

source code 

Method to set the orientation of the document to be landscape

To Do: make this for a page rather than the document

addTable(self, resource=None, raw_data=None, list_fields=None, report_groupby=None, report_hide_comments=False)

source code 

Method to create a table that will be inserted into the document

Parameters:
  • resource - A S3Resource object
  • list_Fields - A list of field names
  • report_groupby - A field name that is to be used as a sub-group All the records that share the same report_groupby value will be clustered together
  • report_hide_comments - Any comment field will be hidden

    This uses the class S3PDFTable to build and properly format the table. The table is then built and stored in the document flow ready for generating the pdf.

    If the table is too wide for the page then it will automatically adjust the margin, font or page orientation. If it is still too wide then the table will be split across multiple pages.

extractrHeader(self, rHeader)

source code 

Method to convert the HTML generated for a rHeader into PDF

addrHeader(self, resource=None, raw_data=None, list_fields=None, report_hide_comments=False)

source code 

Method to create a rHeader table that is inserted into the document

Parameters:
  • resource - A S3Resource object
  • list_Fields - A list of field names
  • report_hide_comments - Any comment field will be hidden

    This uses the class S3PDFTable to build and properly format the table. The table is then built and stored in the document flow ready for generating the pdf.

addPlainTable(self, text, style=None, append=True)

source code 

addParagraph(self, text, style=None, append=True)

source code 

Method to create a paragraph that may be inserted into the document

Parameters:
  • text - The text for the paragraph
  • append - If True then the paragraph will be stored in the document flow ready for generating the pdf.

    @return The paragraph

    This method can return the paragraph rather than inserting into the document. This is useful if the paragraph needs to be first inserted in another flowable, before being added to the document. An example of when this is useful is when large amounts of text (such as a comment) are added to a cell of a table.

addSpacer(self, height, append=True)

source code 

Add a spacer to the story

addOverlay(self, callback, data)

source code 

Add an overlay to the page

addBoxes(self, cnt, append=True)

source code 

Add square text boxes for text entry to the story

throwPageBreak(self)

source code 

Method to force a page break in the report

changePageTitle(self, newTitle)

source code 

Method to force a page break in the report

getStyledTable(self, table, colWidths=None, rowHeights=None, style=[])

source code 

Method to create a simple table

getTableMeasurements(self, tempTable)

source code 

Method to calculate the dimensions of the table

cellStyle(self, style, cell)

source code 

Add special styles to the text in a cell

addCellStyling(self, table, style)

source code 

Add special styles to the text in a table

setHeaderBanner(self, image)

source code 

Method to add a banner to a page used by pageHeader

pageHeader(self, canvas, doc)

source code 

Method to generate the basic look of a page. It is a callback method and will not be called directly

pageFooter(self, canvas, doc)

source code 

Method to generate the basic look of a page. It is a callback method and will not be called directly

buildDoc(self)

source code 

Method to build the PDF document. The response headers are set up for a pdf document and the document is then sent

@return the document as a stream of characters

@todo add a proper template class so that the doc.build is more generic