Monday, March 2, 2009

Creating an image file based on plain text from AX

For the new version of Logica's electronic invoice handling module (eScan) I needed to create a tiff image file from plain text.

Here is a short example on how you can do that through CLR from X++:
static void createTiffFromText(Args _args)
FileName outputFileName = @'C:\Test\MyNewImage.tiff';
str sampleText = "My sample text...";
System.Drawing.Bitmap bitmap;
System.Drawing.Graphics graphics;
bitmap = new System.Drawing.Bitmap(220, 50);
graphics = System.Drawing.Graphics::FromImage(bitmap
graphics.FillRectangle(System.Drawing.Brushes::get_Yellow(), 0, 0, 220, 50);
new System.Drawing.Font("Verdana", 18),
new System.Drawing.SolidBrush(System.Drawing.Color::get_Black()), 0 ,0);
bitmap.Save(outputFileName, System.Drawing.Imaging.ImageFormat::get_Tiff());
// Show the image


Henrik Marx Larsen said...

Just out of curiosity. Are you converting text to TIFF because you invoice only supports this format.

I would probably just have created XHTML and used the web browser viewer with a stylesheet or XSLT...

Maybe I am missing a point!?

Palle Agermark said...

Well, the TIFF format was given in the task I had to solve, but XHTML or XSLT would have been an exellent choice.

We dissplay our invoice images through a browser, but currently we are scanning and creating only TIFF files. We are however looking into supporting other formats during these processes.