Xpertdoc Image Demo

This sample demonstrates how easy it is to add an image dynamically to a document from a C# project by referencing an assembly produced with Xpertdoc Studio 2007. This is useful if the C# project provides to the template an image that differs, for example, from a week to another.

In this sample, the graph is built with datas coming from an Excel file and the resulting Image is passed to the template.

1. First of all, we need to create a Xpertdoc template by clicking the Convert button. Convert Button
2. Then, you need to go to the Xpertdoc Properties and click on the Custom object Button to add a Custom object. Properties Button Custom Object Button
3. Add an Image Custom Object and click OK. Create a custom object
4. Click on the Imports/Usings Button and add a Using for the System.Drawing namespace. Imports/Using Button Add a using to System.Drawing
5. You can now add an Xpertdoc Image to the template by clicking on the Insert Image Button. Insert Image Button
6. Refer to the custom object you created in step 3. Use the name that you put in the Custom Object's Name Property. Image Code
7. Now, you need to compile the Xpertdoc template to get an assembly which will be referenced from the C# application. Click on the compile button to generate the assembly. Compile Button
8. The assembly will be located in the Template Output folder that you can configure in the Xpertdoc Options. Click on the Options Button and look for the Template Output folder property. The name of the assembly is the name of the template with a DLL extension. Options Button Xpertdoc Options
9. Start your Visual Studio project and add a reference to the assembly. Add a reference to the assembly
10. In the Visual Studio project, add a reference to the namespace of the template. Add a using to the namespace
11. To generate the document with an image, you must first instanciate an object of the template, then assign an Image to the graphic Custom Object. Set an output stream by calling the SetOutputStream method that takes a stream as a parameter and call the Execute method to generate the document. Execute the template to the generate a document
You can now open the generated document and see your image. Please note that the graphic does not come from the template but from the C# application and is passed through an Image object.

Download source code
Return to the list of samples

Ask a question / Get Support