Dumping a Template

<< Click to Display Table of Contents >>

Navigation:  dycodoc Template Processing > Template Processing Tutorial >

Dumping a Template

Previous pageReturn to chapter overviewNext page

"Dumping a Template" means that a template will be inserted into a VPE document. The following is the most simple approach.

Some notes:

You may set the values for any field, even if a field is not used in a template - and therefore is not present. No error will occur.

A template can only be dumped into the document into which it had been loaded, e.g. report1.LoadTemplate("some.tpl"), report2.DumpTemplate() is not possible, only report1.DumpTemplate() is allowed.

You can dump one and the same template as often into a document as you like. Each time before you call DumpTemplate() you can assign new values to fields.
Call the VPE API method PageBreak(), before dumping a template a second time, to ensure that the template is dumped into a new page at the end of the document.

VPE is case insensitive regarding Field and Data Source names, e.g. "Sender:Name" and "sender:name" are the same Fields for VPE.

 

 

Sample Code for the VPE Control

// The following procedure will be used for many of the following

// samples. It sets the values of the sample2.fld to some dummy data:

Private Sub SetFields(tpl As TVPETemplate)

 tpl.SetFieldAsString "Sample2", "Recipient:Company", "IDEAL Software"

 tpl.SetFieldAsString "Sample2", "Recipient:Title", "Mr. "

 tpl.SetFieldAsString "Sample2", "Recipient:Surname", "Miller"

 tpl.SetFieldAsString "Sample2", "Recipient:Title", "Carl"

 tpl.SetFieldAsString "Sample2", "Recipient:Street", "Helmholtzstr. 6"

 tpl.SetFieldAsString "Sample2", "Recipient:ZIP", "41464"

 tpl.SetFieldAsString "Sample2", "Recipient:City", "Neuss"

 tpl.SetFieldAsString "Sample2", "Recipient:Country", "Germany"

 tpl.SetFieldAsString "Sample2", "Sender:Account", "pakzadeh"

 tpl.SetFieldAsString "Sample2", "Sender:Dial-Through", "742"

 tpl.SetFieldAsString "Sample2", "Sender:Surname", "Pakzadeh"

 tpl.SetFieldAsString "Sample2", "Sender:Name", "Paymand"

tpl.SetFieldAsString "Sample2", "Sender:Signature", "\dycodoc\samples\pakzadeh.jpg"

 tpl.SetFieldAsString "Sample2", "Sender:Title", "Dr. "

tpl.SetFieldAsString "Sample2", "GoodByePhrase", "You will be informed about the further progress."

End Sub

 

// Main Program

// First of all, we declare an object variable for a template object:

Dim tpl as TVPETemplate

 

// Next, you create a VPE Document with a single blank page:

VPE.OpenDoc

 

// Afterwards we load the template file into memory:

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

 

// If the LoadTemplate() call had failed, an exception would have

// occurred... Now the template has been loaded into memory and is

// ready to be processed. Fill the Fields with values:

SetFields(tpl)

 

// Dump the template into the VPE Document

VPE.DumpTemplate(tpl)

 

// We can show now the preview for the VPE Document we just created:

VPE.Preview

 

 

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

// The following function will be used for many of the following

// samples. It sets the values of the sample2.fld to some dummy data:

void SetFields(VpeHandle hTpl)

{

VpeSetTplFieldAsString(hTpl, "Sample2", "Recipient:Company", "IDEAL Software");

 VpeSetTplFieldAsString(hTpl, "Sample2", "Recipient:Title", "Mr. ");

 VpeSetTplFieldAsString(hTpl, "Sample2", "Recipient:Surname", "Miller");

 VpeSetTplFieldAsString(hTpl, "Sample2", "Recipient:Name", "Carl");

VpeSetTplFieldAsString(hTpl, "Sample2", "Recipient:Street", "Helmholtzstr. 6");

 VpeSetTplFieldAsString(hTpl, "Sample2", "Recipient:ZIP", "41464");

 VpeSetTplFieldAsString(hTpl, "Sample2", "Recipient:City", "Neuss");

 VpeSetTplFieldAsString(hTpl, "Sample2", "Recipient:Country", "Germany");

 VpeSetTplFieldAsString(hTpl, "Sample2", "Sender:Account", "pakzadeh");

 VpeSetTplFieldAsString(hTpl, "Sample2", "Sender:Dial-Through", "742");

 VpeSetTplFieldAsString(hTpl, "Sample2", "Sender:Surname", "Pakzadeh");

 VpeSetTplFieldAsString(hTpl, "Sample2", "Sender:Name", "Paymand");

VpeSetTplFieldAsString(hTpl, "Sample2", "Sender:Signature", "\\dycodoc\\samples\\pakzadeh.jpg");

 VpeSetTplFieldAsString(hTpl, "Sample2", "Sender:Title", "Dr. ");

VpeSetTplFieldAsString(hTpl, "Sample2", "GoodByePhrase", "You will be informed about the further progress.");

}

 

// Main Program

// First of all, we declare an object handle for a template object:

VpeHandle hTpl;

 

// Next, you create a VPE Document with a single blank page:

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

 

// Afterwards we load the template file into memory:

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

if (hTpl == NULL)

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

 

// Now the template has been loaded into memory and is

// ready to be processed. Fill the Fields with values:

SetFields(hTpl);

 

 

// Dump the template into the VPE Document

VpeDumpTemplate(hDoc, hTpl);

 

// We can show now the preview for the VPE Document we just created:

VpePreviewDoc(hDoc, NULL, VPE_SHOW_NORMAL);

 

 

The resulting VPE Preview will look like this:

sample2 vpe

 

 

Summary

The basic steps to use a template are:

1.Create a VPE Document with OpenDoc()

2.Load the template file with LoadTemplate()

3.Fill the Fields with values using SetFieldAsString() or SetFieldAsInteger()

4.Dump the template into the VPE Document with DumpTemplate()

5.Show the preview for the VPE Document with Preview(), or print it without showing a preview by calling PrintDoc() instead