File merging with Dycodoc template and text files

Knowledge exchange related to the VPE Report Engine and PDF Library

Moderator: IDEAL Software Support

File merging with Dycodoc template and text files

Postby voodoo » Tue Jan 24, 2006 11:13 am

It's possible to realize file merging with dycodoc and VPE ? For example, I have a template file created with Dycodoc, a letter with several fields in it. This letter is to be mailed to 10, 100 ... 1000 different customers. The values for the fields is obviously different for each customer. So, I have a text file with the corresponding group of values to be assigned to each letter. I want preview and print all the generated letters all at once. How can I do this?

Many thanks in advance
Robert
voodoo
 
Posts: 1
Joined: Tue Jan 24, 2006 10:45 am

Postby IDEAL Software Support » Tue Jan 24, 2006 4:26 pm

Each time you dump a template into a VPE document, the template is appended to the end of the document.

So you can load the template once, and set the field values each time to the new data. Afterwards you dump the template into the document.

The schematic sequence of function calls is:

// Open a VPE document
VPE.OpenDoc()

// Load the dycodoc template
tpl = VPE.LoadTemplate("xyz.tpl")

while (data available)
{
// Set all fields to appropriate values
tpl.SetFieldAsString("table xyz", "field xyz", "some value")
etc. etc.

VPE.DumpTemplate(tpl)

// Except for the last data record, add a new blank page
if (data available)
VPE.PageBreak()
}

// The document is complete, now do something with the document,
// for example print it, send it by e-mail, write it as PDF, etc.
VPE.WriteDoc("xyz.pdf")

// Now close the document
VPE.CloseDoc()


This way all letters end up in a single document. If you require to have each letter in a separate document, you must open and close the document for each letter separately:

while (data available)
{
// Open a VPE document
VPE.OpenDoc()

// Load the dycodoc template
tpl = VPE.LoadTemplate("xyz.tpl")

// Set all fields to appropriate values
tpl.SetFieldAsString("table xyz", "field xyz", "some value")
etc. etc.

VPE.DumpTemplate(tpl)

// do something with the document, for example print it,
// send it by e-mail, write it as PDF, etc.
VPE.WriteDoc("xyz.pdf")

// Now close the document
VPE.CloseDoc()
}
IDEAL Software Support
 
Posts: 1622
Joined: Thu Nov 18, 2004 4:03 pm


Return to VPE Open Forum

Who is online

Users browsing this forum: No registered users and 91 guests