I have a Word doc I am using as a template with text delimited by “[[” and “]]” to create pseudo-fields, which I am filling in with data from a DB via the Word module.
Once the document is created and filled with data I am converting it to PDF, with the PDF module.
Here is my problem. I have 3 address fields which may or may not be all populated. I have put them all on the same line to avoid nasty white space, e.g.
[[City]], [[State]] [[Zip]]
If the value of addr2 is not nothing, then I am inserting a vbCrLf and then the info for addr2. Same with addr3.
The issue I am having is, I am getting square boxes in the Word and PDF doc, depending on which piece I use (either vbCr, vbLf, or vbCrLf). If I use vbLf, the Word doc does not reflect the CR, but the PDF looks great. If I use the vbCr, the Word doc looks great but the PDF has boxes in it.
There must be some way around this, right?
Any help would be greatly appreciated.
We’re looking into the issue, thanks. But first, why aren’t you using merge fields + MergeField event, but using pseudo-fields?
Good question. I was not aware of the merge fields option, however, we already have templates set up with the pseudo fields. Also, if we use merge fields, it seems that if we have multiple fields of the same name, we need to enumerate them (i.e. , etc.). Is that right?
If you mean repeatable data, then you only need to place into the document its repeatable part. For example, if you need to fill a table with addresses, simply create merge fields for one row and mark beginning and end of the row with two special merge fields. Then run the Document.MailMerge.ExecuteWithRegions method to perform mail merge.
The MergeField event allows to control populating the fields. You can manually set a text to insert depending on some conditions.
Refer here to obtain more info:
Regarding your first question, use of the ControlChar class would not cause appearance of any garbage like the square boxes. Please have a look at this example demonstrating use of this class and the merge fields as applied to your task. Note how easily it can be accomplished using Aspose.Word. The example was written in C#, but I can rewrite it for you if you need it in VB.