pdfme.page
- class pdfme.page.PDFPage(base, width, height, margin_top=0, margin_bottom=0, margin_left=0, margin_right=0)
Bases:
objectClass that represents a PDF page, and has methods to add stream parts into the internal page PDF Stream Object, and other things like fonts, annotations and images.
This object have
xandycoordinates used by thepdfme.pdf.PDFinsance that contains this page. This point is calledcursorin this class.- Parameters
base (PDFBase) – [description]
width (Number) – [description]
height (Number) – [description]
margin_top (Number, optional) – [description]. Defaults to 0.
margin_bottom (Number, optional) – [description]. Defaults to 0.
margin_left (Number, optional) – [description]. Defaults to 0.
margin_right (Number, optional) – [description]. Defaults to 0.
- property y
- Returns
The current vertical position of the page’s cursor, from top (0) to bottom. This is different from
_yattribute, the position from bottom (0) to top.- Return type
Number
- go_to_beginning()
Method to set the position of the cursor’s page to the origin point of the page, considering this page margins. The origin is at the left-top corner of the rectangle that will contain the page’s contents.
- add(content)
Method to add some bytes (if a string is passed, it’s transformed into a bytes object) representing a stream portion, into this page’s PDF internal Stream Object.
- Parameters
content (str, bytes) – the stream portion to be added to this page’s stream.
- Returns
the id of the portion added to the page’s stream
- Return type
int
- add_font(font_ref, font_obj_id)
Method to reference a PDF font in this page, that will be used inside this page’s stream.
- Parameters
font_ref (str) – the
refattribute of thepdfme.fonts.PDFFontinstance that will be referenced in this page.font_obj_id (PDFRef) – the object id of the font being referenced here, already added to a
pdfme.base.PDFBaseinstance.
- add_annot(obj, rect)
Method to add a PDF annotation to this page.
The
objectdict should have the keys describing the annotation to be added. By default, this object will have the following key/values by default:Type = /AnnotandSubtype = /Link. You can include these keys inobjectif you want to overwrite any of the default values for them.- Parameters
obj (dict) – the annotation object.
rect (list) – a list with the following information about the annotation: [x, y, width, height].
- add_link(uri_id, rect)
Method to add a link annotation (a URI that opens a webpage from the PDF document) to this page.
- Parameters
uri_id (PDFRef) – the object id of the action object created to open this link.
rect (list) – a list with the following information about the annotation: [x, y, width, height].
- add_reference(dest, rect)
Method to add a reference annotation (a clickable area, that takes the user to a destination) to this page.
- Parameters
dest (str) – the name of the dest being referenced.
rect (list) – a list with the following information about the annotation: [x, y, width, height].
- add_image(image_obj_id, width, height)
Method to add an image to this page.
The position of the image will be the same as
xandycoordinates of this page.- Parameters
image_obj_id (PDFRef) – the object id of the image PDF object.
width (int, float) – the width of the image.
height (int, float) – the height of the image.