Modifying VPE Objects in a Document

<< Click to Display Table of Contents >>

Navigation:  dycodoc Template Processing > VPE Object Processing >

Modifying VPE Objects in a Document

Previous pageReturn to chapter overviewNext page

Example, which makes the background of an object - which already has been inserted into a VPE Document - drawn in red color. In the following sample, we insert a VPE Text Object (with the text "Hello World!") into a document by calling the VPE API directly.

We retrieve the VPE Object handle from the document with the property "LastInsertedObject".

Sample Code for the VPE Control

Dim obj as TVPEObject

 

// Insert an object into the document:

VPE.Write 1, 1, VFREE, VFREE, "Hello World!"

 

// Retrieve the Object-Handle of the last inserted object:

obj = VPE.LastInsertedObject

 

// Now modify the object:

obj.BkgMode = VBKG_SOLID

obj.BkgColor = COLOR_RED

 

// Refresh the preview (only neccessary, if the modified object is

// on the visible page and the preview is shown):

VPE.Refresh

 

 

Sample Code for the VPE DLL (C/C++)

// Insert an object into the document:

VpePrint(hDoc, 1, 1, "Hello World!");

 

// Retrieve the Object-Handle:

long hObj = VpeGetLastInsertedObject(hDoc);

 

// Now modify the object:

VpeSetBkgMode(hObj, VBKG_SOLID);

VpeSetBkgColor(hObj, COLOR_RED);

 

// Refresh the preview (only neccessary, if the modified object is

// on the visible page and the preview is shown):

VpeRefreshDoc(hDoc);

 

In addition to the property LastInsertedObject VPE provides the property FirstObject which retrieves the first VPE Object of the current page of the VPE Document you are working on. VPE Objects themselves own the property NextObject. Both properties together allow to iterate through all objects of a page / document.

Looking at the previous sample you will ask youself "So far so good, but if I dumped a template into a document, how can I retrieve VPE object handles from the inserted objects? The property 'LastInsertedObject' won't help me, since it references only the last inserted object and not the whole group of template objects. The properties FirstObject / NextObject provide all objects on a page, but I need discrete informations about the objects that have been created from a template."

You are right. But VPE offers a special method to retrieve for each template object the corresponding objects that were inserted into the VPE document.

We speak about multiple corresponding objects, because a single Text Object or Rich Text Object might have been split over multiple pages. This can happen if it contains huge parts of text or if its position was very near to the bottom margin. When an object is split over multiple pages, each splitted object is a new distinct object.

In the following sample we will dump the template into a VPE Document. Afterwards we search the template VPE Objects "RichText5" and "Picture2". We will then retrieve the coordinates of the corresponding VPE Objects which had been inserted into the document. Having their coordinates, we will draw two crossing lines above these objects, calling the VPE API directly.

The whole strikeout process is done in the procedure "StrikeOutObject".

 

 

Sample Code for the VPE Control

// Search an object in the template by a given name.

// Then the corresponding objects, which already have been inserted into

// the VPE document, are stroke out by two crossing lines.

Private Sub StrikeOutObject(Doc As VPE, tpl As TVPETemplate, obj_name As String)

 Dim TplObj, DocObj As TVPEObject

 Dim left, top, right, bottom As Long

 Dim i As Integer

 

 // Find the object in the template

 Set TplObj = tpl.FindVpeObject(obj_name)

 

 // Did we find it?

 If TplObj.ObjectHandle <> 0 Then

         // Yes, found it. Due to a possible auto break the object could

         // have been inserted multiple times into the VPE document.

         // Find ALL inserted objects and strike them through

         For i = 0 To TplObj.InsertedVpeObjectCount

                 // Get the i-th object and its coordinates:

                 Set DocObj = TplObj.InsertedVpeObject(i)

 

                 left = DocObj.nLeft

                 top = DocObj.nTop

                 right = DocObj.nRight

                 bottom = DocObj.nBottom

 

                 // Go to the page where the i-th object has been inserted:

                 Doc.CurrentPage = TplObj.InsertedVpeObjectPageNo(i)

 

                 // Draw two crossing lines into the object's rectangle:

                 Call Doc.VpeLine(left, top, right, bottom)

                 Call Doc.VpeLine(right, top, left, bottom)

         Next i

 End If

End Sub

 

// Main Program

Dim tpl as TVPETemplate

Dim obj as TVPEObject

VPE.OpenDoc

tpl = VPE.LoadTemplate("\dycodoc\samples\sample2.tpl")

SetFields(tpl)   // this procedure had been declared in the very first sample

VPE.DumpTemplate(tpl)

StrikeOutObject(VPE, tpl, "RichText5")

StrikeOutObject(VPE, tpl, "Picture2")

VPE.Preview

 

 

Sample Code for the VPE DLL (C/C++)

// Search an object in the template by a given name.

// Then the corresponding objects, which already have been inserted into

// the VPE document, are stroke out by two crossing lines.

void StrikeOutObject(VpeHandle hDoc, VpeHandle hTpl, char *obj_name)

{

 // Find the object in the template

 VpeHandle hTplObj = VpeFindTplVpeObject(hTpl, obj_name);

 if (!hTplObj)

         return;

         

 // We found it:

 // Due to a possible auto break the object could have

 // been inserted multiple times into the VPE document.

 // Find ALL inserted objects and strike them through

 for (long i = 0; i < VpeGetInsertedVpeObjectCount(hTplObj); i++)

 {

         RECT rc;

 

         // Get the i-th object and its coordinates:

         VpeHandle hObj = VpeGetInsertedVpeObject(hTplObj, i);

         rc.left = VpeGetObjLeft(hObj);

         rc.top = VpeGetObjTop(hObj);

         rc.right = VpeGetObjRight(hObj);

         rc.bottom = VpeGetObjBottom(hObj);

 

         // Go to the page where the i-th object has been inserted:

         VpeGotoPage(hDoc, VpeGetInsertedVpeObjectPageNo(hTplObj, i));

 

         // Draw two crossing lines into the object's rectangle:

         VpeLine(hDoc, rc.left, rc.top, rc.right, rc.bottom);

         VpeLine(hDoc, rc.right, rc.top, rc.left, rc.bottom);

 }

}

 

// Main Program

VpeHandle hTpl;

VpeHandle hDoc = VpeOpenDoc(hWnd, "Sample", 0);

hTpl = VpeLoadTemplate(hDoc, "\\dycodoc\\samples\\Sample2.tpl");

if (hTpl == NULL)

  return;                // an error had occurred, e.g. the file was not found

SetFields(hTpl);        // this procedure had been declared in the very first sample

VpeDumpTemplate(hDoc, hTpl);

StrikeOutObject(hDoc, hTpl, "RichText5")

StrikeOutObject(hDoc, hTpl, "Picture2")

VpePreviewDoc(hDoc, NULL, VPE_SHOW_NORMAL);

 

 

Important Note

It is possible to modify an object's property, even if the object does not provide this property. In this case the call will have simply no effect.

 

Example:

Your object handle belongs to a Line Object. Lines have no background color property. So the following call is possible, but will have no effect: BkgColor = COLOR_RED

There are no methods to modify a VPE object's text content or text properties. Workaround: for VPE objects that reside in a document (the following said is not possible if they reside in a template!) you can use the following workaround: simply delete the object from the document (call VpeDeleteObject()) adjust the document properties as required and insert a new text object into the document.

 

WARNING: Modifying any of the following properties for Text-, RTF- and FormField-Objects that reside already in a VPE Document might cause that the text does not fit anymore into the object's rectangle, since the object is not re-rendered. Text will be clipped (i.e. skipped) then!

PenSize

FontName

FontSize

Charset

Bold

Italic

Rotation (works only for VPE Objects which reside in a template!)

 

For FormFields, the above rule extends in addition to the following properties:

CharCount

DividerPenSize

AltDividerNPosition

AltDividerPenSize

BottomLinePenSize

FormFieldFlags

 

NOTE: You can modify without problems any of the above properties for objects which reside in a template before dumping it, if nRight and nBottom of the object are set to VFREE.