| |
- builtins.object
-
- Bitmap
- Char
- Doc
- Font
- KDTree
- Output
- Page
class Doc(builtins.object) |
|
A Doc object is used for storing a document (like a PDF).
doc.pages contains the number of pages in the document,
and doc.filename the name of the file the document was
created (loaded) from. If the document was created from
an image file, the number of pages is always 1 |
|
Methods defined here:
- __iter__(...)
- x.__iter__() <==> iter(x)
- __next__(...)
- x.__next__() <==> next(x)
- getInfo(...)
- getInfo(key)
Retrieve some information about a document. For PDF files, key
can have the following values:
"title", "subject", "keywords", "author", "creator", "producer",
"creationdate", "moddate", "linearized", "tagged", "encrypted",
"oktoprint", "oktocopy", "oktochange", "oktoaddnotes", "version".
If the "oktocopy" digital rights management flag is set to "no", then the
pdf parser won't allow you to access the PDF file. Trying to extract pages
from it will raise an exception.
- getPage(...)
- getPage(nr)
Get one page from a document file. The nr parameter specifies
which page to retrieve. Counting starts at 1, so the first page
can be retrieved by
page = doc.getPage(1)
.
You can find out how many pages a document contains by querying
its pages field (doc.pages)
- setparameter(...)
- setparameter(key, value)
Pass a parameter or setting to the document parser. Unlike
the module level setparameter() function, the parameters set
using setparameter will only be valid for the object itself
during its lifetime.
|
class KDTree(builtins.object) |
|
A kdtree is a two dimensional tree for storing bounding box data |
|
Methods defined here:
- add_box(...)
- put(bbox, data)
Add a rectangular area to the tree. All queries within that area
will subsequently return 'data'
- find(...)
- find(x,y)
Look for a coordinate in the kdtree. It will return last inserted object covering that position, or None.
|
class Output(builtins.object) |
|
An Output object can be used as parameter to the render()
call of a page. It's not possible to create this type of
object directly (i.e., from a class), however you can
use a PassThrough() device to pass things over to Python.
Examples for classes implementing the Output class are:
ImageList, SWF, PlainText and PassThrough. |
|
Methods defined here:
- endpage(...)
- endpage()
Ends a page in the output device. This function should be called
once for every startpage()
- fill(...)
- fill()
fill a polygon with a color
- fillbitmap(...)
- fillbitmap()
fill a polygon with a bitmap pattern
- save(...)
- save(filename)
Saves the contents of an output device to a file
Depending on what the output device is, the contents
of the file may be plain text, an image, an SWF file,
etc.
For the ImageList device, several files (named
filename.1.png, filename.2.png etc.) might be created)
- setparameter(...)
- setparameter(key, value)
Set a output-device dependent parameter
- startpage(...)
- startpage(width, height)
Starts a new page/frame in the output device.
The usual way to render documents is to start a new page in the
device for each page in the document:
for pagenr in range(1,doc.pages+1):
page = doc.getPage(pagenr)
output.startpage(page.width, page.height)
page.render(output)
output.endpage()
It is, however, also possible to render more than one document page
to a single output page. E.g. for side-by-side or book views.
- stroke(...)
- stroke()
stroke a polygon with a color
|
class Page(builtins.object) |
|
A Page object contains a single page of a document.
page.width and page.height (or page.size) contain the
page dimensions. page.nr is the number of the page, and
page.doc is the parent document. |
|
Methods defined here:
- asImage(...)
- asImage(width, height)
Creates a bitmap from a page. The bitmap will be returned as a string
containing RGB triplets. The bitmap will be rescaled to the specified width and
height. The aspect ratio of width and height doesn't need to be the same
as the page.
- draw(...)
- draw(output)
Renders a page to the rendering backend specified by the output
parameter, with the default for page width and height.
- render(...)
- render(output, move=(0,0), clip=None)
Renders a page to the rendering backend specified by the output
parameter. Rendering consists of calling a number of functions on the
output device, see the description of the "PassThrough" device.
The page may be shifted to a given position using the move parameter,
and may also be clipped to a specific size using the clip parameter.
The clipping operation is applied after the move operation.
If you don't need to specify custom page sizes or clippings, use
page.draw instead.
| |