public static void Run(string inputfilename, string outputfilename)
        {
            // Load the document from file:
            var document = (Document)XamlServices.Load(inputfilename);

            // Write the document to PDF:
            PdfModelWriter.WriteDocument(document, outputfilename);
        }
        public static void Run(string outputfilename)
        {
            // Get the model, either by creating one or by deserializing one:
            var document = GetDocumentModel();

            // You can search and update the model in memory before generating the PDF. I.e:
            // Find the rectangle with id=titlebox and set/change it's radius:
            foreach (Rectangle item in document.All().Where(item => item.Id == "titlebox"))
            {
                item.Radius = "10";
            }

            // If you have localized data, you can provide an IDictionary<string,string> implementation
            // to resolve ContentKeys in the document model. Here we create the dictionary:
            var localizedSource = new Dictionary <string, string>();

            localizedSource["bodytext"] = "*************".Replace("*", "The quick brown fox jumps over the lazy dog. ");

            // You can use it for localized data, but also for any dynamic data. I.e:
            localizedSource["datetime"] = DateTime.Now.ToString();

            // Generate the PDF document:
            var pagenum = 0;

            using (var stream = new FileStream(outputfilename, FileMode.Create, FileAccess.Write))
            {
                // Create a new PdfModelWriter:
                var writer = new PdfModelWriter();

                // Set a ContentSource dictionary to resolve contentKeys which allow
                // for localization of the content of your documents:
                writer.ContentSource = localizedSource;

                // We can still intervene on document and page creation with callback actions. I.e:
                // Set a Document callback to dynamically inject an image when creating the document:
                writer.OnDocumentBegin = (docwriter, doc) =>
                {
                    var imgref = docwriter.AddImage(Properties.Resources.ImgV);
                    writer.SetReferenceObject("dynimg1", imgref);
                };

                // Or add page numbers:
                writer.OnPageEnd = (pagewriter, page) =>
                {
                    // Write "1" in the right bottom corner of the page, right-aligned:
                    pagewriter.DrawTextblock(pagewriter.Width - 120, 40, (++pagenum).ToString(), 60, (PdfTextOptions)writer.GetReferenceObject("t0"), 0.0, +1);
                };

                // Finally, write the document to the stream:
                writer.Write(document, stream);
            }
        }