VPE Control (Java)

<< Click to Display Table of Contents >>

Navigation:  Getting Started >

VPE Control (Java)

Previous pageReturn to chapter overviewNext page

VPE does only provide a preview window for displaying, browsing and printing documents on the Windows platform. Therefore there are two versions of the VPE Control: a GUI and a Non-GUI version.

The GUI version is only available for Windows and can be found in the file
<vpe-installation-directory> / deploy / vpegui.jar

The Non-GUI version is available for all platforms and can be found in the file
<vpe-installation-directory> / deploy / vpe.jar

The Non-GUI version is also useful on Windows, when used in a server application, or if no preview Window is required. Please note that a common way of using VPE is to export a created document to PDF and to use a PDF Reader (like Adobe Acrobat) for displaying and printing the document. The API of both JAR files is identical. Only methods and properties  related to previewing and printing are left out in the Non-GUI version.

Make sure that any of the two VPE JAR files is in your classpath.

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

import com.idealSoftware.vpe.*;

import com.idealSoftware.vpe.events.*;

 

class VpeTest {

 
public static void main(String[] args) {
       VpeControl doc = new VpeControl();
       doc.openDoc();

         doc.writeBox(1, 1, 5, 1.5, "Hello World!");

         doc.line(1.5, 3, 5, 6.5);

         doc.writeDoc("hello world.pdf");

         doc.closeDoc();

}

}

Compile with: javac -classpath ..\deploy\vpe.jar VpeTest.java

Execute with: java -cp .;../deploy/vpe.jar VpeTest

Make sure to adjust the classpath, so that it points to the VPE JAR file in your environment.

 

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

Please note that the major difference to the previous version is one additional line of code with a call to “Doc.preview()” (and a method pause()).

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

import com.idealSoftware.vpe.*;

import com.idealSoftware.vpe.events.*;

import java.io.*;

 

class VpeGuiTest {

 
static void pause()
{
       try
       {
               System.out.printf("\n\n  Press ENTER...");
               System.in.read();
               while (System.in.available() > 0)
                       System.in.read();        // flush the buffer        
       }
       catch (IOException e)
       {
               System.out.printf("Error\n");
       }
}
 
public static void main(String[] args) {
       VpeControl doc = new VpeControl();
       doc.openDoc();
       doc.print(1, 1, "Hello World!");
       doc.preview();
       doc.writeDoc("hello world.pdf");
       pause();
       doc.closeDoc();
}

}

Compile with: javac -classpath ..\deploy\vpegui.jar VpeGuiTest.java

Execute with: java -cp .;../deploy/vpegui.jar VpeGuiTest

Make sure to adjust the classpath, so that it points to the VPE JAR file in your environment.

 

Congratulations, this is your first Java program using VPE! The source code is self-explanatory, the only thing to explain are the numbers in the calls to writeBox() and line(): these are the coordinates in centimeters relative to the upper left corner of the page. The coordinates are organized as (left, top, right, bottom).

Note: you can also switch to inch units, so the coordinates are not in centimeters, but in inches.

Please note that this is a very very simple demo. For example, VPE can compute the width and height of a text object depending on the text-length and the chosen font. So you can position objects dynamically at runtime relative to each other, in contrast to a static layout.

We recommend to continue with the tutorial created by running the "vpedemo" executable, which comes with VPE. The demo named "Capabilities + Precision" creates a document with a handy 5-page tutorial (beginning on page 2 of the document).

The very detailed and in-depth explanation of all aspects and features of VPE can be found in this document in the chapter “Programming Techniques”.