VDP data - aurigma/direct-mail-app-sample GitHub Wiki
Some products may require personalization of each printed copy with personal data, for example, for mass mailing. To avoid creating and customizing each product separately, Customer's Canvas allows you to use VDP data.
Customer's Canvas supports several scenarios for using VDP. This sample uses the method of saving VDP data to the design in a DataSet
. You will learn more details in the description of the Approval page.
The scheme of the DataSet
looks as follows:
"dataSet": {
"surfacesData": [{
// Render only the first three product pages.
"surfaceBinding": {
"surfaceIndexes": [0,1,2]
},
// Define the personalization data for variable fields.
"data": [
{
"Name": { "text": "John Smith" }
},
{
"Name": { "text": "Anne Bennet" }
},
{
"Name": { "text": "Alex Ford" }
}
]
}]
}
The saved DataSet
is applied at the rendering of print-ready files.
In the sample, we use the following types of variable fields: text, in-string placeholder, image, and image placeholder. When creating a dataset, different field types use different formats.
For text and in-string placeholders: "Name": { "text": "Anne Bennet" }
For images and image placeholders:
- private images from Asset Storage:
"Photo": { "image": "user:<Full path>" }
- public images from Asset Storage:
"Photo": { "image": "public:<Full path>" }
- external images not associated with the Customer's Canvas:
"Photo": { "image": "<externalUrl>" }
The sample uses predefined data simulating the data of real recipients.
The list of recipients is located in the file recipients.json in the project folder App_Data. If needed, you can modify this file and add or remove recipients. To update recipients in the database, you need to create a new migration by using the ImportRecipientsFromJsonFile
method of the DbInitializer
class.
private List<RecipientDal> ImportRecipientsFromJsonFile()
{
var assemblyLocation = AppDomain.CurrentDomain.BaseDirectory;
var recipientJson = System.IO.File.ReadAllText(System.IO.Path.Combine(assemblyLocation, "App_Data/Recipients" +"/recipients.json"));
var recipients = JsonConvert.DeserializeObject<List<RecipientDal>>(recipientJson);
return recipients;
}
Each recipient has a number of pre-filled fields, such as name, address, signature, etc. The full specification you can see in recipients.json or in the domain entity Recipient
.
The application binds all recipients to one specific list.
We have prepared several images simulating assets for recipients. The available images, as well as the list of recipients, are stored in App_Data in the PrivateImages folder.
Information about the images, such as the name, the path to the image, etc., is stored in the database and recorded in the RecipientImage
table. The data is prepared in advance. The code for data creation is also located in the DbInitializer
class:
new RecipientImageDal
{
Id = new Guid("70c7d323-fa21-4728-bafb-94ce744827f5"),
Name = "Same image.svg",
Path = "App_Data/PrivateImages",
CreationTime = new DateTime(2024, 8, 22, 4, 33, 56, 146, DateTimeKind.Utc),
RecipientListId = new Guid("5146239e-aa2f-4797-a250-1ddeed5dee53")
}
As well as the recipients, the images are linked to the only available list.
During the submission, the prepared images are imported into Asset Storage. The general algorithm looks as follows:
- Recipient lists linked to the current project are retrieved from the database.
- A single collection is created from all the images linked to the received lists.
- Based on the information about the images obtained in the previous steps, the images are requested from the application's file system (ImageService).
- A folder for private images is created (obtained) in Asset Storage. The name of this folder is the ID of the current project.
- The images already existing in this folder are requested.
- If the images have been imported earlier, for example, if the user has already submitted the lists and returned to the Settings page, then the request is terminated.
- If there are not enough images in Asset Storage, each missing image will be imported through the Asset Processor with the endpoint
/api/processor/v1/private-images/import
. The request code contains the adapter:PrivateImageProcessorAdapter
.
Next, these images will be used as part of the current project to generate previews and print files.