Example #1
0
        public static Boolean FarpointToPDF0(FpSpread fpSpread, String pdfFile, Int32 reportIndex)
        {
            Boolean flag = false;

            if (fpSpread == null || fpSpread.Sheets.Count == 0)
            {
                return(flag);
            }
            PrintInfo Info = new PrintInfo();

            Info.CopyFrom(fpSpread.Sheets[0].PrintInfo);
            Info.ShowGrid = false;
            Bitmap Panel = new Bitmap(Info.PaperSize.Width, Info.PaperSize.Height);

            using (Graphics g = Graphics.FromImage(Panel))
            {
                g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                g.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                g.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;

                System.Drawing.Rectangle r = new System.Drawing.Rectangle(
                    Info.Margin.Left,
                    Info.Margin.Top,
                    Info.PaperSize.Width - Info.Margin.Left - Info.Margin.Right,
                    Info.PaperSize.Height - Info.Margin.Top - Info.Margin.Bottom
                    );

                int Foot, Heard;
                Foot  = (int)Math.Round(g.MeasureString(Info.Footer, fpSpread.Font).Height);
                Heard = (int)Math.Round(g.MeasureString(Info.Header, fpSpread.Font).Height);

                r = new System.Drawing.Rectangle(r.X, r.Y + Heard, r.Width, r.Height - Foot - Heard);
                fpSpread.OwnerPrintDraw(g, r, 0, 1);
            }
            Info = null;
            PdfDocument doc = new PdfDocument();

            doc.Pages.Add(new PdfPage());
            XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[0]);
            XImage    img = XImage.FromGdiPlusImage(Panel);

            xgr.DrawImage(img, 0, 0);

            doc.Save(pdfFile);
            doc.Close();
            xgr.Dispose();
            img.Dispose();
            doc.Dispose();
            Panel.Dispose();
            GC.Collect();
            flag = true;
            return(flag);
        }
Example #2
0
        /// <summary>
        /// 导出到PDF
        /// </summary>
        private void ExportToPDF()
        {
            SaveFileDialog FileDialog = new SaveFileDialog();

            FileDialog.Filter           = "PDF文件 (*.pdf)|*.pdf";
            FileDialog.FilterIndex      = 1;
            FileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            FileDialog.RestoreDirectory = true;
            if (FileDialog.ShowDialog() == DialogResult.OK)
            {
                int       Index = FpSpread.Sheets.IndexOf(ActiveSheet);
                PrintInfo Info  = new PrintInfo();
                Info.CopyFrom(ActiveSheet.PrintInfo);
                Info.ShowGrid = false;
                Bitmap Panel = new Bitmap(Info.PaperSize.Width, Info.PaperSize.Height);

                using (Graphics g = Graphics.FromImage(Panel))
                {
                    g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                    g.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                    g.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;

                    Rectangle r = new Rectangle(
                        Info.Margin.Left,
                        Info.Margin.Top,
                        Info.PaperSize.Width - Info.Margin.Left - Info.Margin.Right,
                        Info.PaperSize.Height - Info.Margin.Top - Info.Margin.Bottom
                        );

                    int Foot, FootW, Heard;
                    Foot  = (int)Math.Round(g.MeasureString(Info.Footer, FpSpread.Font).Height);
                    FootW = (int)Math.Round(g.MeasureString(Info.Footer, FpSpread.Font).Width);
                    Heard = (int)Math.Round(g.MeasureString(Info.Header, FpSpread.Font).Height);

                    r = new Rectangle(r.X, r.Y + Heard, r.Width, r.Height - Foot - Heard);
                    FpSpread.OwnerPrintDraw(g, r, Index, 1);
                }

                PdfDocument doc = new PdfDocument();
                doc.Pages.Add(new PdfPage());
                XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[0]);
                XImage    img = XImage.FromGdiPlusImage(Panel);

                xgr.DrawImage(img, 0, 0);

                doc.Save(FileDialog.FileName);
                doc.Close();
                //Panel.Save("", ImageFormat.Jpeg);
                Panel.Dispose();
            }
        }
Example #3
0
        public static Boolean FarpointToImage(Guid documentID, FpSpread FpSpread, String path)
        {
            if (FpSpread == null || FpSpread.Sheets.Count == 0)
            {
                return(false);
            }
            Boolean flag = true;

            try
            {
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                for (int i = 0; i < FpSpread.Sheets.Count; i++)
                {
                    PrintInfo Info = new PrintInfo();
                    Info.CopyFrom(FpSpread.Sheets[i].PrintInfo);
                    Info.ShowGrid = false;
                    Bitmap img = new Bitmap(Info.PaperSize.Width, Info.PaperSize.Height);

                    using (Graphics g = Graphics.FromImage(img))
                    {
                        g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                        g.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                        g.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;

                        System.Drawing.Rectangle r = new System.Drawing.Rectangle(
                            Info.Margin.Left,
                            Info.Margin.Top,
                            Info.PaperSize.Width - Info.Margin.Left - Info.Margin.Right,
                            Info.PaperSize.Height - Info.Margin.Top - Info.Margin.Bottom
                            );

                        int Foot, Heard;
                        Foot  = (int)Math.Round(g.MeasureString(Info.Footer, FpSpread.Font).Height);
                        Heard = (int)Math.Round(g.MeasureString(Info.Header, FpSpread.Font).Height);

                        r = new System.Drawing.Rectangle(r.X, r.Y + Heard, r.Width, r.Height - Foot - Heard);
                        FpSpread.OwnerPrintDraw(g, r, i, 1);
                    }
                    img.Save(Path.Combine(path, documentID.ToString() + "_" + i + ".jpg"), ImageFormat.Jpeg);
                }
            }
            catch
            {
                flag = false;
            }
            return(flag);
        }
Example #4
0
        public PrintInfo getReportSettings()
        {
            reportSettings.CopyFrom(this.report.PrintInfo);

            reportSettings.RepeatColStart = -1;
            reportSettings.RepeatColEnd   = -1;
            reportSettings.RepeatRowStart = -1;
            reportSettings.RepeatRowEnd   = -1;

            reportSettings.ColStart = -1;
            reportSettings.ColEnd   = -1;
            reportSettings.RowStart = -1;
            reportSettings.RowEnd   = -1;

            return(reportSettings);
        }