I’m writing a windows service that’s required to retrieve data from a database, build a document from that data and then fax it. Tiff seems to be the standard for fax images and I know that I can encode an Image object as a tiff.
It would be great if I could build the image object like a document similar to how iTextSharp does it by creating new elements and attaching the elements to a PdfDocument object. My fax documents will be simple but require these things
- Centering a paragraph of text
- Add another image with absolute positioning (logo)
- Simple two column tables for field/value
- Horizontal rules
Creating an HTML document is trivial but .Net doesn’t seem to have a way to render HTML to an image object.
Desirable solutions would be some type of document class in the BCL that could be rendered to an image object where I could encode from there or some type of helper class/library or Image wrapper to draw these simple elements to an image instance.
Does either solution exist or is there maybe something else I could consider?
So I did find a solution that allows me to build documents with the features that I needed. I ended up using MigraDoc even though it definitely isn’t as elegant as iTextSharp. MigraDoc allowed me to create a System.Drawing.Image object from a Document object using its XGraphics class.
Using a few of the MigraDoc examples (I really wish they had better class library documentation, that was a big con IMHO) I was able to create a TIFF file like this
WriteTiffImage() is used to encode the image as TIFF and then do the final write to disc.
I probably didn’t even need to do the scaling but it was in the example and worked out fine for what I wanted to accomplish.