Exemplo n.º 1
0
        static void Main(string[] args)
        {
            // try
            // {
            // Create an invoice form with the sample invoice data.
            var invoice = new InvoiceForm("../../../../assets/xml/invoice.xml");

            // Create the document using MigraDoc.
            var document = invoice.CreateDocument();

            document.UseCmykColor = true;

#if DEBUG
            MigraDoc.DocumentObjectModel.IO.Xml.DdlWriter.WriteToFile(document, "MigraDoc.xml");

            MigraDoc.DocumentObjectModel.Document document3 = null;

            using (StreamReader sr = File.OpenText("MigraDoc.xml"))
            {
                var errors = new MigraDoc.DocumentObjectModel.IO.DdlReaderErrors();
                var reader = new MigraDoc.DocumentObjectModel.IO.Xml.DdlReader(sr, errors);

                document3 = reader.ReadDocument();

                using (StreamWriter sw = new StreamWriter("MigraDoc.xml.error"))
                {
                    foreach (MigraDoc.DocumentObjectModel.IO.DdlReaderError error in errors)
                    {
                        sw.WriteLine("{0}:{1} {2} {3}", error.SourceLine, error.SourceColumn, error.ErrorLevel, error.ErrorMessage);
                    }
                }
            }
#endif

            // Create a renderer for PDF that uses Unicode font encoding.
            var pdfRenderer = new PdfDocumentRenderer(true);

            // Set the MigraDoc document.
            pdfRenderer.Document = document3;

            // Create the PDF document.
            pdfRenderer.RenderDocument();

            // Save the PDF document...
            var filename = "Invoice.pdf";
#if DEBUG
            // I don't want to close the document constantly...
            filename = "Invoice-" + Guid.NewGuid().ToString("N").ToUpper() + ".pdf";
#endif
            pdfRenderer.Save(filename);
            // ...and start a viewer.
            Process.Start(filename);
            //}
            //catch (Exception ex)
            //{
            //  Console.WriteLine(ex.Message);
            //Console.ReadLine();
            //}
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            try
            {
                // Create an invoice form with the sample invoice data.
                var invoice = new InvoiceForm("../../../../assets/xml/invoice.xml");

                // Create the document using MigraDoc.
                var document = invoice.CreateDocument();
                document.Document.UseCmykColor = true;

#if DEBUG
                // For debugging only...
                MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToFile(document.Document, "MigraDoc.mdddl");
                //var document2 = MigraDoc.DocumentObjectModel.IO.DdlReader.DocumentFromFile("MigraDoc.mdddl");
                //document = document2;
                // With PDFsharp 1.50 beta 3 there is a known problem: the blank before "by" gets lost while persisting as MDDDL.

                MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToFile(document.Document.Clone(), "MigraDoc2.mdddl");
#endif

#if true
                // Create a renderer for PDF that uses Unicode font encoding.
                var pdfRenderer = new PdfDocumentRenderer(true);

                // Set the MigraDoc document.
                pdfRenderer.Document = document.Document /*.Clone()*/;
                // $THHO TODO Investigate why Clone() leads to an unusable document.

                // Create the PDF document.
                pdfRenderer.RenderDocument();

                // Save the PDF document...
                var filename = "Invoice.pdf";
#if DEBUG
                // I don't want to close the document constantly...
                filename = "Invoice-" + Guid.NewGuid().ToString("N").ToUpper() + ".pdf";
#endif
                pdfRenderer.Save(filename);
                // ...and start a viewer.
                Process.Start(filename);
#else
                // Create a renderer for PDF that uses Unicode font encoding.
                // Save the PDF document...
                var filename = "Invoice.pdf";
#if DEBUG
                // I don't want to close the document constantly...
                filename = "Invoice-" + Guid.NewGuid().ToString("N").ToUpper() + ".pdf";
#endif
                document.MakePdf(filename, true);
#endif
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadLine();
            }
        }
Exemplo n.º 3
0
    static void Main()
    {
      try
      {
        // Create a invoice form with the sample invoice data
        InvoiceForm invoice = new InvoiceForm("../../invoice.xml");

        // Create a MigraDoc document
        Document document = invoice.CreateDocument();
        document.UseCmykColor = true;

#if DEBUG
        // for debugging only...
        MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToFile(document, "MigraDoc.mdddl");
        document = MigraDoc.DocumentObjectModel.IO.DdlReader.DocumentFromFile("MigraDoc.mdddl");
#endif

        // Create a renderer for PDF that uses Unicode font encoding
        PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true);

        // Set the MigraDoc document
        pdfRenderer.Document = document;

        // Create the PDF document
        pdfRenderer.RenderDocument();

        // Save the PDF document...
        string filename = "Invoice.pdf";
#if DEBUG
        // I don't want to close the document constantly...
        filename = "Invoice-" + Guid.NewGuid().ToString("N").ToUpper() + ".pdf";
#endif
        pdfRenderer.Save(filename);
        // ...and start a viewer.
        Process.Start(filename);
      }
      catch (Exception ex)
      {
        Console.WriteLine(ex.Message);
        Console.ReadLine();
      }
    }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            try
            {
                // Create a invoice form with the sample invoice data
                InvoiceForm invoice = new InvoiceForm("in/invoice.xml");

                // Create a MigraDoc document
                Document document = invoice.CreateDocument();
                document.UseCmykColor = true;

                Directory.CreateDirectory("out");
#if DEBUG
                // for debugging only...
                MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToFile(document, "out/MigraDoc.mdddl");
                document = MigraDoc.DocumentObjectModel.IO.DdlReader.DocumentFromFile("out/MigraDoc.mdddl");
#endif

                // Create a renderer for PDF that uses Unicode font encoding
                PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true);

                // Set the MigraDoc document
                pdfRenderer.Document = document;

                // Create the PDF document
                pdfRenderer.RenderDocument();

                // Save the PDF document...
                string filename = "out/invoice-" + DateTimeOffset.UtcNow.Ticks.ToString() + ".pdf";

                pdfRenderer.Save(filename);

                //Process.Start(filename);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.WriteLine("Press ENTER key to EXIT...");
            Console.ReadLine();
        }
Exemplo n.º 5
0
        static void Main()
        {
            try
            {
                // Create a invoice form with the sample invoice data
                InvoiceForm invoice = new InvoiceForm("../../invoice.xml");

                // Create a MigraDoc document
                Document document = invoice.CreateDocument();
                document.UseCmykColor = true;

#if DEBUG
                // for debugging only...
                MigraDoc.DocumentObjectModel.IO.DdlWriter.WriteToFile(document, "MigraDoc.mdddl");
                document = MigraDoc.DocumentObjectModel.IO.DdlReader.DocumentFromFile("MigraDoc.mdddl");
#endif

                // Create a renderer for PDF that uses Unicode font encoding
                PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(true);

                // Set the MigraDoc document
                pdfRenderer.Document = document;

                // Create the PDF document
                pdfRenderer.RenderDocument();

                // Save the PDF document...
                string filename = "Invoice.pdf";
#if DEBUG
                // I don't want to close the document constantly...
                filename = "Invoice-" + Guid.NewGuid().ToString("N").ToUpper() + ".pdf";
#endif
                pdfRenderer.Save(filename);
                // ...and start a viewer.
                Process.Start(filename);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadLine();
            }
        }