VPE Python

<< Click to Display Table of Contents >>

Navigation:  How To Use the VPE Control >

VPE Python

Previous pageReturn to chapter overviewNext page

The VPE Control for Python is for version 3.x of Python only.

The class name is VpeControl.

The common sequence of function calls is:

Set the properties for behavior and appearance of VPE before calling the method OpenDoc

Open a document with the method "OpenDoc"

Use all possible methods to insert VPE objects (like Write(), etc.)

Use "PageBreak" to generate new pages

Use "Preview" to show the preview to the user, this is optional

Use "PrintDoc" to print the document, or "WriteDoc()" to export it

Close the document with "CloseDoc"

 

It is only possible to open one document per VPE control. If you want to open multiple documents simultaneously, you need use the same number of VPE controls.

 

Create a file named “VpeTest.py” with the following code:

import os, sys

from VpeControl import *

 

doc = VpeControl()

doc.OpenDoc()

doc.Print(1, 1, "Hello World!")

doc.WriteDoc("hello world.pdf")

doc.CloseDoc()

Execute with: python VpeTest.py

This example is very simple. The document is opened, the text "Hello World!" is inserted at position (1, 1) and afterwards the document is written as PDF file.

 

For the Windows platform, here is a version which shows a preview window:

Create a file named “VpeGuiTest.py” with the following code:

import os, sys

from time import sleep

from VpeControl import *

 

doc = VpeControl()

doc.OpenDoc()

doc.Print(1, 1, "Hello World!")

doc.WriteDoc("hello world.pdf")

 

# Note that the DispatchAllMessages()-loop is required to pump messages from the

# Windows operating system to the preview. This keeps the preview alive.

doc.Preview()

abort = False

while not abort:

 abort = doc.DispatchAllMessages()

 sleep(0.01)

 

Because Python is windowless, you need to pump Windows messages to the preview as shown above.

For a detailed explanation of the basic programming techniques, please continue reading in the "Programmer's Manual" chapter 4 "Programming Techniques".