Using Metafiles

PDF for Silverlight makes it very easy to create documents, mainly because the object model mimics the well-known .NET Graphics model. However, not all methods available in the Graphics class are available in PDF for Silverlight. Plus, you may have existing code that draws to a Graphics object and that you do not want to rewrite even if most methods are very similar.

In these cases, you can reuse your existing .NET code by sending the drawing commands to a Metafile, then rendering the Metafile into PDF for Silverlight using the C1PdfDocument.DrawImage command. This method allows you to expose any graphics you create as images or as PDF documents.

For example, suppose you have an application that generates documents using the PrintDocument pattern of drawing each page into a Graphics object. You could then use the same methods to create a collection of metafiles, one per page, and then convert the list into a PDF document using the following code:

      Visual Basic

      C#

Save the document using the Save method as explained in the quick start topic, Step 3 of 4: Saving the document.

The code gets each metafile on the list, calculates its size in points (each page could have a different size), then draws the metafile into the page. The metafiles could be generated by a reporting engine, drawing or charting program, or any application that can create metafile images.


Send us comments about this topic.
Copyright © GrapeCity, inc. All rights reserved.