private void Button_Click(object sender, RoutedEventArgs e)
        {
            var dlg = new Microsoft.Win32.SaveFileDialog();

            dlg.Filter = "PDF files (*.pdf)|*.pdf";
            //var t = dlg.ShowDialog();
            if (dlg.ShowDialog().Value)
            {
                // create pdf document
                var pdf = new C1PdfDocument();
                pdf.Landscape   = true;
                pdf.Compression = CompressionLevel.NoCompression;

                // render all grids into pdf document
                var options = new PdfExportOptions();
                options.ScaleMode = ScaleMode.ActualSize;
                GridExport.RenderGrid(pdf, _flex1, options);
                pdf.NewPage();
                GridExport.RenderGrid(pdf, _flex2, options);
                pdf.NewPage();
                GridExport.RenderGrid(pdf, _flex3, options);
                pdf.NewPage();
                GridExport.RenderGrid(pdf, _flex4, options);

                // save document
                using (var stream = dlg.OpenFile())
                {
                    pdf.Save(stream);
                }
            }
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var dlg = new Microsoft.Win32.SaveFileDialog();
            dlg.Filter = "PDF files (*.pdf)|*.pdf";
            //var t = dlg.ShowDialog();
            if (dlg.ShowDialog().Value)
            {
                // create pdf document
                var pdf = new C1PdfDocument();
                pdf.Landscape = true;
                pdf.Compression = CompressionLevel.NoCompression;

                // render all grids into pdf document
                var options = new PdfExportOptions();
                options.ScaleMode = ScaleMode.ActualSize;
                GridExport.RenderGrid(pdf, _flex1, options);
                pdf.NewPage();
                GridExport.RenderGrid(pdf, _flex2, options);
                pdf.NewPage();
                GridExport.RenderGrid(pdf, _flex3, options);
                pdf.NewPage();
                GridExport.RenderGrid(pdf, _flex4, options);

                // save document
                using (var stream = dlg.OpenFile())
                {
                    pdf.Save(stream);
                }
            }
        }
        public static void SavePdf(C1FlexGrid flex, Stream s, PdfExportOptions options)
        {
            var pdf = new C1PdfDocument();

            options.KnownPageCount = false;
            RenderGrid(pdf, flex, options);

            // save the PDF document and close the stream
            pdf.Save(s);
            s.Close();
        }
Example #4
0
 public static void SavePdf(C1FlexGrid flex, Stream s)
 {
     var options = new PdfExportOptions();
     SavePdf(flex, s, options);
 }
Example #5
0
        public static void RenderGrid(C1PdfDocument pdf, C1FlexGrid flex, PdfExportOptions options)
        {
            // get rendering options
            if (options == null)
            {
                options = new PdfExportOptions();
            }

            // get root element to lay out the PDF pages
            Panel root = null;
            for (var parent = flex.Parent as FrameworkElement; parent != null; parent = parent.Parent as FrameworkElement)
            {
                if (parent is Panel)
                {
                    root = parent as Panel;
                }
            }

            // get page size
            var rc = pdf.PageRectangle;

            // create panel to hold elements while they render
            var pageTemplate = new PageTemplate();
            pageTemplate.Width = rc.Width;
            pageTemplate.Height = rc.Height;
            pageTemplate.SetPageMargin(options.Margin);
            root.Children.Add(pageTemplate);

            // render grid into PDF document
            var m = options.Margin;
            var sz = new Size(rc.Width - m.Left - m.Right, rc.Height - m.Top - m.Bottom);
            var pages = flex.GetPageImages(options.ScaleMode, sz, 100);
            for (int i = 0; i < pages.Count; i++)
            {
                // skip a page when necessary
                if (i > 0)
                {
                    pdf.NewPage();
                }

                // set content
                pageTemplate.PageContent.Child = pages[i];
                pageTemplate.PageContent.Stretch = options.ScaleMode == ScaleMode.ActualSize
                    ? System.Windows.Media.Stretch.None
                    : System.Windows.Media.Stretch.Uniform;

                // set header/footer text
                pageTemplate.HeaderLeft.Text = options.DocumentTitle;
                if (options.KnownPageCount)
                {
                    pageTemplate.FooterRight.Text = string.Format("Page {0} of {1}",
                        pdf.CurrentPage + 1, pages.Count);
                }
                else
                {
                    pageTemplate.FooterRight.Text = string.Format("Page {0}",
                        pdf.CurrentPage + 1);
                }

                // measure page element
                pageTemplate.UpdateLayout();
                pageTemplate.Arrange(new Rect(0, 0, rc.Width, rc.Height));

                // add to PDF
                pdf.DrawElement(pageTemplate, rc);
            }

            // done with template
            root.Children.Remove(pageTemplate);
        }
        public static void RenderGrid(C1PdfDocument pdf, C1FlexGrid flex, PdfExportOptions options)
        {
            // get rendering options
            if (options == null)
            {
                options = new PdfExportOptions();
            }

            // get root element to lay out the PDF pages
            Panel root = null;

            for (var parent = flex.Parent as FrameworkElement; parent != null; parent = parent.Parent as FrameworkElement)
            {
                if (parent is Panel)
                {
                    root = parent as Panel;
                }
            }

            // get page size
            var rc = pdf.PageRectangle;

            // create panel to hold elements while they render
            var pageTemplate = new PageTemplate();

            pageTemplate.Width  = rc.Width;
            pageTemplate.Height = rc.Height;
            pageTemplate.SetPageMargin(options.Margin);
            root.Children.Add(pageTemplate);

            // render grid into PDF document
            var m     = options.Margin;
            var sz    = new Size(rc.Width - m.Left - m.Right, rc.Height - m.Top - m.Bottom);
            var pages = flex.GetPageImages(options.ScaleMode, sz, 100);

            for (int i = 0; i < pages.Count; i++)
            {
                // skip a page when necessary
                if (i > 0)
                {
                    pdf.NewPage();
                }

                // set content
                pageTemplate.PageContent.Child   = pages[i];
                pageTemplate.PageContent.Stretch = options.ScaleMode == ScaleMode.ActualSize
                    ? System.Windows.Media.Stretch.None
                    : System.Windows.Media.Stretch.Uniform;

                // set header/footer text
                pageTemplate.HeaderLeft.Text = options.DocumentTitle;
                if (options.KnownPageCount)
                {
                    pageTemplate.FooterRight.Text = string.Format("Page {0} of {1}",
                                                                  pdf.CurrentPage + 1, pages.Count);
                }
                else
                {
                    pageTemplate.FooterRight.Text = string.Format("Page {0}",
                                                                  pdf.CurrentPage + 1);
                }

                // measure page element
                pageTemplate.UpdateLayout();
                pageTemplate.Arrange(new Rect(0, 0, rc.Width, rc.Height));

                // add to PDF
                pdf.DrawElement(pageTemplate, rc);
            }

            // done with template
            root.Children.Remove(pageTemplate);
        }
        //-------------------------------------------------------------------------------------------------------
        #region ** object model

        public static void SavePdf(C1FlexGrid flex, Stream s)
        {
            var options = new PdfExportOptions();

            SavePdf(flex, s, options);
        }
Example #8
-1
        public static void SavePdf(C1FlexGrid flex, Stream s, PdfExportOptions options)
        {
            var pdf = new C1PdfDocument();
            options.KnownPageCount = false;
            RenderGrid(pdf, flex, options);

            // save the PDF document and close the stream
            pdf.Save(s);
            s.Close();
        }