Document

class Document

High-level API for creating a document-based canvas.

To use:

  1. Create a document, specifying a stream to store the output.

  2. For each “page” of content:

    1. canvas = doc.beginPage(…)

    2. draw_my_content(canvas)

    3. doc.endPage()

  3. Close the document with doc.close().

skia-python supports with syntax to build a document:

stream = skia.FILEWStream('output.pdf')
with skia.PDF.MakeDocument(stream) as document:
    with document.page(480, 640) as canvas:
        draw(canvas)

Methods

__init__

abort

Call abort() to stop producing the document immediately.

beginPage

Begin a new page for the document, returning the canvas that will draw into the page.

close

Call close() when all pages have been drawn.

endPage

Call endPage() when the content for the current page has been drawn (into the canvas returned by beginPage()).

page

ref

Increment the reference count.

unique

May return true if the caller is the only owner.

unref

Decrement the reference count.

Methods

Document.__init__(*args, **kwargs)
Document.abort(self: skia.Document) None

Call abort() to stop producing the document immediately.

The stream output must be ignored, and should not be trusted.

Document.beginPage(self: skia.Document, width: float, height: float, content: skia.Rect = None) SkCanvas

Begin a new page for the document, returning the canvas that will draw into the page.

The document owns this canvas, and it will go out of scope when endPage() or close() is called, or the document is deleted.

Document.close(self: skia.Document) None

Call close() when all pages have been drawn.

This will close the file or stream holding the document’s contents. After close() the document can no longer add new pages. Deleting the document will automatically call close() if need be.

Document.endPage(self: skia.Document) None

Call endPage() when the content for the current page has been drawn (into the canvas returned by beginPage()).

After this call the canvas returned by beginPage() will be out-of-scope.

Document.page(self: skia.Document, width: float, height: float) (anonymous namespace)::PyAutoDocumentPage
Document.ref(self: skia.RefCntBase) None

Increment the reference count.

Must be balanced by a call to unref().

Document.unique(self: skia.RefCntBase) bool

May return true if the caller is the only owner.

Ensures that all previous owner’s actions are complete.

Document.unref(self: skia.RefCntBase) None

Decrement the reference count.

If the reference count is 1 before the decrement, then delete the object. Note that if this is the case, then the object needs to have been allocated via new, and not on the stack.