예제 #1
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            // render both reports to generate PageImages collections
            _c1rPortrait.Render();
            _c1rLandscape.Render();

            // start a new pdf document
            _c1pdf.Clear();
            int cnt = 0;

            // add portrait pages
            _c1pdf.PaperKind = PaperKind.Letter;
            foreach (Image img in _c1rPortrait.PageImages)
            {
                if (cnt > 0)
                {
                    _c1pdf.NewPage();
                }
                _c1pdf.Landscape = false;
                _c1pdf.DrawImage(img, _c1pdf.PageRectangle);
                cnt++;
            }

            // add landscape pages
            foreach (Image img in _c1rLandscape.PageImages)
            {
                if (cnt > 0)
                {
                    _c1pdf.NewPage();
                }
                _c1pdf.Landscape = true;
                _c1pdf.DrawImage(img, _c1pdf.PageRectangle);
                cnt++;
            }

            // save the document
            string appPath = Application.StartupPath + "\\mixed.pdf";

            _c1pdf.Save(appPath);

            DialogResult dr = MessageBox.Show("Resulting sample pdf found at:\r\n\r\n" +
                                              appPath + "\r\n\r\nDo you wish to launch?", "", MessageBoxButtons.YesNo);

            if (dr == DialogResult.Yes)
            {
                Process p = new Process();
                p.StartInfo.FileName = appPath;
                p.Start();
            }
        }
예제 #2
0
        bool ExportDocument()
        {
            // get pdf file name
            using (SaveFileDialog dlg = new SaveFileDialog())
            {
                dlg.Filter = "Portable Document File (*.pdf)|*.pdf";
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    // create preview document
                    PrintDocument          doc  = Editor.PrintDocument;
                    PrintController        pc   = doc.PrintController;
                    PreviewPrintController pcpv = new PreviewPrintController();
                    doc.PrintController = pcpv;
                    doc.Print();
                    doc.PrintController = pc;

                    // create pdf document
                    using (C1.C1Pdf.C1PdfDocument pdf = new C1.C1Pdf.C1PdfDocument())
                    {
                        // add pages to pdf document
                        bool firstPage = true;
                        foreach (PreviewPageInfo page in pcpv.GetPreviewPageInfo())
                        {
                            pdf.PageSize = new SizeF(
                                page.PhysicalSize.Width * 0.72f,
                                page.PhysicalSize.Height * 0.72f);
                            if (!firstPage)
                            {
                                pdf.NewPage();
                            }
                            pdf.DrawImage(page.Image, pdf.PageRectangle);
                            firstPage = false;
                        }

                        // save pdf file
                        try
                        {
                            pdf.Save(dlg.FileName);
                            string       msg = string.Format(Resources.ExportPdf_msg, Path.GetFileName(dlg.FileName));
                            DialogResult dr  = MessageBox.Show(this, msg, Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                            if (dr == DialogResult.Yes)
                            {
                                Process.Start(dlg.FileName);
                            }
                            return(true);
                        }
                        catch (Exception x)
                        {
                            string msg = x.Message;
                            MessageBox.Show(this, msg, Application.ProductName);
                            return(false);
                        }
                    }
                }
            }

            // failed
            return(false);
        }
예제 #3
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            // render both reports to generate PageImages collections
            _c1rPortrait.Render();
            _c1rLandscape.Render();

            // start a new pdf document
            _c1pdf.Clear();
            int cnt = 0;

            // add portrait pages
            _c1pdf.PaperKind = PaperKind.Letter;
            foreach (Image img in _c1rPortrait.PageImages)
            {
                if (cnt > 0)
                {
                    _c1pdf.NewPage();
                }
                _c1pdf.Landscape = false;
                _c1pdf.DrawImage(img, _c1pdf.PageRectangle);
                cnt++;
            }

            // add landscape pages
            foreach (Image img in _c1rLandscape.PageImages)
            {
                if (cnt > 0)
                {
                    _c1pdf.NewPage();
                }
                _c1pdf.Landscape = true;
                _c1pdf.DrawImage(img, _c1pdf.PageRectangle);
                cnt++;
            }

            // save the document
            string tempdir = Application.ExecutablePath.Substring(0,
                                                                  Application.ExecutablePath.LastIndexOf("\\") + 1);

            _c1pdf.Save(tempdir + "mixed.pdf");
            Process.Start(tempdir + "mixed.pdf");
        }
예제 #4
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            // render both reports to generate PageImages collections
            _c1rPortrait.Render();
            _c1rLandscape.Render();

            // start a new pdf document
            _c1pdf.Clear();
            int cnt = 0;

            // add portrait pages
            _c1pdf.PaperKind = PaperKind.Letter;
            foreach (Image img in _c1rPortrait.PageImages)
            {
                if (cnt > 0)
                {
                    _c1pdf.NewPage();
                }
                _c1pdf.Landscape = false;
                _c1pdf.DrawImage(img, _c1pdf.PageRectangle);
                cnt++;
            }

            // add landscape pages
            foreach (Image img in _c1rLandscape.PageImages)
            {
                if (cnt > 0)
                {
                    _c1pdf.NewPage();
                }
                _c1pdf.Landscape = true;
                _c1pdf.DrawImage(img, _c1pdf.PageRectangle);
                cnt++;
            }

            // save the document
            _c1pdf.Save(@"c:\temp\mixed.pdf");
        }
예제 #5
0
        private void ConvertToPdf(List <Image> images)
        {
            RectangleF rect      = imagePdfDocument.PageRectangle;
            bool       firstPage = true;

            foreach (var selectedimg in images)
            {
                if (!firstPage)
                {
                    imagePdfDocument.NewPage();
                }
                firstPage = false;
                rect.Inflate(-72, -72);
                imagePdfDocument.DrawImage(selectedimg, rect);
            }
        }
예제 #6
0
            private void DrawPageImage(C1.C1Pdf.C1PdfDocument pdf, int index)
            {
                // get image bounds
                RectangleF rcBounds = pdf.PageRectangle;

                rcBounds.Inflate(-72, -72);

                // calculate zoom factor
                if (index == 0)
                {
                    // get size of largest image
                    SizeF szMax = Size.Empty;
                    foreach (Image page in _images)
                    {
                        szMax.Height = Math.Max(szMax.Height, page.Height);
                        szMax.Width  = Math.Max(szMax.Width, page.Width);
                    }

                    // get size of page bounds
                    SizeF szPage = rcBounds.Size;

                    // calculate zoom so largest image doesn't overflow the page
                    _zoom = 1;
                    float zh = szPage.Width / szMax.Width;
                    float zv = szPage.Height / szMax.Height;
                    if (zh < 1 || zv < 1)
                    {
                        _zoom = Math.Min(zh, zv);
                    }
                }

                // draw grid image
                RectangleF rc  = rcBounds;
                Image      img = _images[index] as Image;

                rc.Width  = (int)(img.Width * _zoom);
                rc.Height = (int)(img.Height * _zoom);
                if (index > 0)
                {
                    pdf.NewPage();
                }
                pdf.DrawImage(img, rc);
            }
예제 #7
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            // start document
            _c1pdf.Clear();
            _c1pdf.Security.AllowPrint = false;
            //_c1pdf.Security.UserPassword = "******";
            //_c1pdf.Landscape = true;

            // build page and chart rectangles
            RectangleF rcPage = _c1pdf.PageRectangle;

            rcPage.Inflate(-60, -72);
            rcPage.X = 72;
            RectangleF rcChart = new RectangleF(rcPage.X, rcPage.Y, 160, 160);

            // show title
            Font       font = new Font("Tahoma", 16, FontStyle.Bold);
            string     text = "Pdf charts created with the C1Chart control.";
            RectangleF rc   = rcPage;

            rc.Y = rcPage.Y - 24;
            _c1pdf.DrawString(text, font, Brushes.DarkGray, rc);

            // scan controls on the selected tab page and render charts
            foreach (Control c in tabControl1.SelectedTab.Controls)
            {
                // skip invisible controls
                if (!c.Visible)
                {
                    continue;
                }

                // get chart control
                C1.Win.C1Chart.C1Chart     c2d = c as C1.Win.C1Chart.C1Chart;
                C1.Win.C1Chart3D.C1Chart3D c3d = c as C1.Win.C1Chart3D.C1Chart3D;

                // get metafile from chart control
                label1.Text = string.Format("Getting image from {0}...", c.Name);
                label1.Update();
                Metafile meta = null;
                if (c2d != null)
                {
                    meta = (Metafile)c2d.GetImage();
                }
                if (c3d != null)
                {
                    meta = (Metafile)c3d.GetImage();
                }

                // make sure we got the metafile
                if (meta == null)
                {
                    continue;
                }

                // draw it, frame it, and move on
                label1.Text = string.Format("Exporting {0}...", c.Name);
                label1.Update();
                _c1pdf.DrawImage(meta, rcChart);
                _c1pdf.DrawRectangle(Pens.SteelBlue, rcChart);
                rcChart = NextChartRect(rcChart, rcPage);
            }
            label1.Text = string.Empty;

            // save document and show it
            string tempdir = Application.ExecutablePath.Substring(0,
                                                                  Application.ExecutablePath.LastIndexOf("\\") + 1);
            string fileName = string.Format(tempdir + @"{0}.pdf", tabControl1.SelectedTab.Text);

            _c1pdf.Save(fileName);
            Process.Start(fileName);
        }
예제 #8
0
        private void DumpMetas(string mask)
        {
            Cursor = Cursors.WaitCursor;

            _c1pdf.Clear();
            _c1pdf.Compression = C1.C1Pdf.CompressionEnum.None;
            //_c1pdf.Compression = C1.C1Pdf.CompressionEnum.BestCompression;
            Random rnd  = new Random();
            Font   font = new Font("Courier New", 9, FontStyle.Bold);

            // look for emf files in the executable directory
            string path  = Path.GetDirectoryName(Application.ExecutablePath);
            bool   first = true;

            string[] files = Directory.GetFiles(path, mask);
            foreach (string fileName in files)
            {
                statusBar1.Text = string.Format("Exporting {0}...", Path.GetFileName(fileName));
                Application.DoEvents();

                // new page
                if (!first)
                {
                    _c1pdf.NewPage();
                }
                first = false;

                // load metafile
                Metafile meta = (Metafile)Metafile.FromFile(fileName);

                // get metafile size in points
                SizeF szPage = GetImageSizeInPoints(meta);
                Console.WriteLine("Adding page {0:f2}\" x {1:f2}\"", szPage.Width / 72f, szPage.Height / 72f);

                // size page to metafile
                _c1pdf.PageSize = szPage;

                // draw metafile on the page
                RectangleF rc = _c1pdf.PageRectangle;
                _c1pdf.FillRectangle(Brushes.AntiqueWhite, rc);
                _c1pdf.DrawImage(meta, rc);
                _c1pdf.DrawString(fileName, font, Brushes.Black, rc);

                // draw thumbnail at random place
                rc.Width  /= 5;
                rc.Height /= 5;
                rc.X       = rnd.Next((int)(szPage.Width - rc.Width));
                rc.Y       = rnd.Next((int)(szPage.Height - rc.Height));
                _c1pdf.FillRectangle(Brushes.White, rc);
                _c1pdf.DrawImage(meta, rc);
                _c1pdf.DrawRectangle(Pens.Black, rc);

                // add outline entry if there's more than one page
                if (files.Length > 1)
                {
                    _c1pdf.AddBookmark(Path.GetFileName(fileName), 0, 0);
                }
            }

            // show the result
            statusBar1.Text = "Saving...";
            SaveAndShow(@"c:\temp\test\metas.pdf");
            Cursor          = Cursors.Default;
            statusBar1.Text = "Ready";
        }