Adding images

Contents
[ ]

Aspose.OMR allows you to customize questionnaires, answer sheets, and other forms by adding images (such as your company logo) to them. In addition to describing the element in the source code, the full path to each image file must be directly passed to the form generator.

Image paths can be provided with:

  • A string array in GenerateTemplate method.
    It only works with text markup files and does not allow you to configure page settings.
  • ImagesPaths property of GlobalPageSettings object. Full paths to images are provided as an array of strings.
    This is a universal approach that works with all types of sources, and also allows you to customize page settings.
  • Aspose.OMR.Api.ImageCollection object - a collection of key-value pairs where the key contains the image file name and the value contains the binary content (System.IO.MemoryStream) of the image file.

Example

Template source code:

?image=aspose-logo.png
	align=center
?text=Customer Satisfaction Survey
	align=center
	font_size=16
	font_style=bold
?image=vignette.png
	align=center

Generate and save the printable form, providing images by file paths:

string workingDirectory = System.IO.Directory.GetCurrentDirectory();
Aspose.OMR.Generation.GlobalPageSettings globalPageSettings = new Aspose.OMR.Generation.GlobalPageSettings() {
	PaperSize = Aspose.OMR.Generation.PaperSize.Tabloid,
	BubbleColor= Aspose.OMR.Generation.Color.Red,
	ImagesPaths = new string[] {
		System.IO.Path.Combine(workingDirectory, "aspose-logo.png"),
		@"C:\Users\Public\Pictures\vignette.png"
	}
};
Aspose.OMR.Api.OmrEngine omrEngine = new Aspose.OMR.Api.OmrEngine();
Aspose.OMR.Generation.GenerationResult generationResult = omrEngine.GenerateTemplate("source.txt", globalPageSettings);
generationResult.Save("", "OMR-Form");

Generate and save the printable form, loading images from memory:

string sourceCode = File.ReadAllText(@"source.txt");
var buffer = Encoding.UTF8.GetBytes(sourceCode);
ImageCollection images = new ImageCollection();
images.Add("aspose-logo.png", new MemoryStream(File.ReadAllBytes(System.IO.Path.Combine(workingDirectory, "aspose-logo.png"))));
images.Add("vignette.png", new MemoryStream(File.ReadAllBytes(@"C:\Users\Public\Pictures\vignette.png")));
Aspose.OMR.Api.OmrEngine omrEngine = new Aspose.OMR.Api.OmrEngine();
using(MemoryStream source = new MemoryStream(buffer))
{
	Aspose.OMR.Generation.GenerationResult generationResult = omrEngine.GenerateTemplate(source, images);
	generationResult.Save("", "OMR-Form");
}