예제 #1
0
        private void SetPageSize(XmlDocument doc)
        {
            XPageSettings ps = new XPageSettings();

            string pageKind     = ((XmlElement)doc.GetElementsByTagName("page")[0]).GetAttribute("kind").ToString();
            string pageWidth    = ((XmlElement)doc.GetElementsByTagName("page")[0]).GetAttribute("width").ToString();
            string pageHeight   = ((XmlElement)doc.GetElementsByTagName("page")[0]).GetAttribute("height").ToString();
            string marginLeft   = ((XmlElement)doc.GetElementsByTagName("margins")[0]).GetAttribute("left").ToString();
            string marginRight  = ((XmlElement)doc.GetElementsByTagName("margins")[0]).GetAttribute("right").ToString();
            string marginTop    = ((XmlElement)doc.GetElementsByTagName("margins")[0]).GetAttribute("top").ToString();
            string marginBottom = ((XmlElement)doc.GetElementsByTagName("margins")[0]).GetAttribute("bottom").ToString();
            string landScape    = ((XmlElement)doc.GetElementsByTagName("landscape")[0]).GetAttribute("value").ToString();

            ps.PaperSize.Kind = (PaperKind)Enum.Parse(typeof(PaperKind), pageKind);

            if (ps.PaperSize.Kind == PaperKind.Custom)
            {
                ps.PaperSize.Height = int.Parse(pageWidth);
                ps.PaperSize.Width  = int.Parse(pageHeight);
            }

            ps.Margins.Left   = int.Parse(marginLeft);
            ps.Margins.Right  = int.Parse(marginRight);
            ps.Margins.Top    = int.Parse(marginTop);
            ps.Margins.Bottom = int.Parse(marginBottom);

            ps.Landscape        = bool.Parse(landScape);
            m_ActualPageSetting = ps;
        }
예제 #2
0
        /// <summary>
        /// 创建指定页的图元数据
        /// </summary>
        /// <param name="page">页面对象</param>
        /// <param name="DrawMargin">是否绘制边距线</param>
        /// <returns>包含图元数据的字节数组</returns>
        public byte[] GetMetafile(PrintPage page, bool DrawMargin)
        {
            XPageSettings pageSettings = page.PageSettings;

            System.Drawing.Imaging.Metafile meta = null;
            using (DeviceContexts dc = DeviceContexts.CreateCompatibleDC(IntPtr.Zero))
            {
                System.IO.MemoryStream stream = new System.IO.MemoryStream();
                meta = new System.Drawing.Imaging.Metafile(
                    stream,
                    dc.HDC,
                    new System.Drawing.Rectangle(
                        0,
                        0,
                        (int)page.PageSettings.ViewPaperWidth,
                        (int)page.PageSettings.ViewPaperHeight),
                    //System.Drawing.Imaging.MetafileFrameUnit.Document );
                    PrintUtil.ConvertUnit(myDocument.DocumentGraphicsUnit));
                using (System.Drawing.Graphics g2 = System.Drawing.Graphics.FromImage(meta))
                {
                    if (intBackColor.A != 0)
                    {
                        g2.Clear(this.intBackColor);
                    }

                    g2.PageUnit = myDocument.DocumentGraphicsUnit;

                    PageFrameDrawer drawer = new PageFrameDrawer();
                    drawer.DrawMargin   = DrawMargin;
                    drawer.BackColor    = System.Drawing.Color.Transparent;
                    drawer.BorderColor  = this.intBorderColor;
                    drawer.BorderWidth  = 1;
                    drawer.LeftMargin   = (int)page.ViewLeftMargin;
                    drawer.TopMargin    = (int)page.ViewTopMargin;
                    drawer.RightMargin  = (int)page.ViewRightMargin;
                    drawer.BottomMargin = (int)page.ViewBottomMargin;

                    drawer.Bounds = new System.Drawing.Rectangle(
                        0,
                        0,
                        (int)pageSettings.ViewPaperWidth,
                        (int)pageSettings.ViewPaperHeight);
                    drawer.BackgroundImage = this.PageBackgroundImage;
                    g2.ScaleTransform(this.XZoomRate, this.YZoomRate);
                    drawer.DrawPageFrame(g2, System.Drawing.Rectangle.Empty);

                    DrawPage(page, g2, page.Bounds, true);
                }
                meta.Dispose();
                dc.Dispose();
                return(stream.ToArray());
            }
        }
예제 #3
0
        public void WriteStartDocument(DomDocument document)
        {
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }
            this.Writer.CollectionInfo   = false;
            this.Writer.Info["title"]    = document.Info.Title;
            this.Writer.Info["subject"]  = document.Info.Description;
            this.Writer.Info["author"]   = document.Info.Author;
            this.Writer.Info["creatim"]  = document.Info.CreationTime;
            this.Writer.Info["comment"]  = document.Info.Comment;
            this.Writer.Info["operator"] = document.Info.Operator;
            this.Writer.WriteStartDocument();
            XPageSettings ps = document.PageSettings;

            // 输出纸张大小
            this.Writer.WriteKeyword("paperw" + ToTwips(ps.ViewPaperWidth));
            this.Writer.WriteKeyword("paperh" + ToTwips(ps.ViewPaperHeight));
            // 横向打印
            if (ps.Landscape)
            {
                this.Writer.WriteKeyword("landscape");
            }
            // 左右页边距
            this.Writer.WriteKeyword("margl" + ToTwips(ps.ViewLeftMargin));
            this.Writer.WriteKeyword("margr" + ToTwips(ps.ViewRightMargin));

            //int fix = 80 ;
            int fix = 0;

            if (this.ForcePage)
            {
                fix = 80;
            }

            this.Writer.WriteKeyword("margt" + this.ToTwips(ps.ViewTopMargin - fix));
            this.Writer.WriteKeyword("margb" + this.ToTwips(ps.ViewBottomMargin - fix));
            if (this.OutputHeaderFooter)
            {
                if (ps.FooterDistance > 0)
                {
                    this.Writer.WriteKeyword("footery" + this.ToTwips(ps.ViewFooterDistance - fix));
                }
                if (ps.HeaderDistance > 0)
                {
                    this.Writer.WriteKeyword("headery" + this.ToTwips(ps.ViewHeaderDistance - fix));
                }
            }
        }
예제 #4
0
        ///// <summary>
        ///// 无作为的初始化对象
        ///// </summary>
        //public PrintPage()
        //{
        //}

        public PrintPage(
            IPageDocument document,
            XPageSettings pageSettings,
            PrintPageCollection pages,
            int headerHeight,
            int footerHeight)
        {
            myDocument      = document;
            myPageSettings  = pageSettings;
            myOwnerPages    = pages;
            intHeaderHeight = headerHeight;
            intFooterHeight = footerHeight;
            intWidth        = (int)myPageSettings.ViewClientWidth;
            // 对标准页高缩小点,避免由于某个页高正好等于标准页高时该页最下面
            // 的线条无法显示和打印。(通融才能从容)
            intHeight = this.ViewStandardHeight - 10;
        }
예제 #5
0
        /// <summary>
        /// 创建指定页的BMP图片对象
        /// </summary>
        /// <param name="page">页面对象</param>
        /// <param name="DrawMargin">是否绘制页边距线</param>
        /// <returns>创建的BMP图片对象</returns>
        public System.Drawing.Bitmap GetPageBmp(PrintPage page, bool DrawMargin)
        {
            XPageSettings pageSettings = page.PageSettings;
            double        rate         = GraphicsUnitConvert.GetRate(
                myDocument.DocumentGraphicsUnit,
                System.Drawing.GraphicsUnit.Pixel);

            int width  = (int)Math.Ceiling(pageSettings.ViewPaperWidth / rate);
            int height = (int)Math.Ceiling(pageSettings.ViewPaperHeight / rate);

            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(width, height);
            using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp))
            {
                if (intBackColor.A != 0)
                {
                    g.Clear(this.intBackColor);
                }

                g.PageUnit = myDocument.DocumentGraphicsUnit;

                PageFrameDrawer drawer = new PageFrameDrawer();
                drawer.DrawMargin   = DrawMargin;
                drawer.BackColor    = System.Drawing.Color.Transparent;
                drawer.BorderColor  = this.intBorderColor;
                drawer.BorderWidth  = 1;
                drawer.LeftMargin   = (int)page.ViewLeftMargin;
                drawer.TopMargin    = (int)page.ViewTopMargin;
                drawer.RightMargin  = (int)page.ViewRightMargin;
                drawer.BottomMargin = (int)page.ViewBottomMargin;

                drawer.Bounds = new System.Drawing.Rectangle(
                    0,
                    0,
                    (int)page.ViewPaperWidth,
                    (int)page.ViewPaperHeight);
                drawer.BackgroundImage = this.PageBackgroundImage;
                drawer.DrawPageFrame(g, System.Drawing.Rectangle.Empty);

                DrawPage(page, g, page.Bounds, true);
            }
            return(bmp);
        }
예제 #6
0
 protected void FilePageSettings(object sender, WriterCommandEventArgs args)
 {
     if (args.Mode == WriterCommandEventMode.QueryState)
     {
         args.Enabled = false;
         if (args.Document != null)
         {
             args.Enabled = args.DocumentControler.EditorControlReadonly == false;
         }
     }
     else if (args.Mode == WriterCommandEventMode.Invoke)
     {
         args.Result = false;
         using (dlgPageSetup dlg = new dlgPageSetup())
         {
             dlg.PageSettings = args.Document.PageSettings.Clone();
             if (dlg.ShowDialog(args.EditorControl) == DialogResult.OK)
             {
                 XPageSettings ps = dlg.PageSettings;
                 if (args.Document.BeginLogUndo())
                 {
                     args.Document.UndoList.AddProperty(
                         "PageSettings",
                         args.Document.PageSettings,
                         ps,
                         args.Document);
                     args.Document.EndLogUndo();
                 }
                 args.Document.PageSettings = ps;
                 args.Document.UpdateContentVersion();
                 if (args.EditorControl != null)
                 {
                     args.EditorControl.RefreshDocument();
                     args.EditorControl.Invalidate();
                 }
                 args.Result = true;
             }
         }
     }
 }
예제 #7
0
 /// <summary>
 /// 显示打印机选中对话框
 /// </summary>
 /// <param name="specialPageIndex">指定的页码</param>
 /// <param name="ownerForm">主窗体</param>
 /// <returns>用户是否成功的设置</returns>
 public bool Prompt(int specialPageIndex)
 {
     using (System.Windows.Forms.PrintDialog dlg
                = new System.Windows.Forms.PrintDialog())
     {
         dlg.UseEXDialog = true;
         string printerName = this.PrinterSettings.PrinterName;
         if (printerName == null || printerName.Trim().Length == 0)
         {
             printerName = this.RuntimeMainDocument.PageSettings.PrinterName;
         }
         if (printerName != null && printerName.Trim().Length > 0)
         {
             this.PrinterSettings.PrinterName = printerName;
         }
         dlg.PrinterSettings = this.PrinterSettings;
         if (specialPageIndex < 0)
         {
             dlg.AllowCurrentPage = true;
             dlg.AllowSelection   = false;
             dlg.AllowSomePages   = true;
         }
         if (dlg.ShowDialog(this.WriterControl) == System.Windows.Forms.DialogResult.OK)
         {
             this.PrinterName     = null;
             this.PaperSourceName = null;
             XPageSettings settings = new XPageSettings();
             settings.StdPageSettings =
                 dlg.PrinterSettings.DefaultPageSettings;
             //doc.PrinterSettings.
             return(true);
         }
         else
         {
             // 用户取消操作
             return(false);
         }
     }
 }
예제 #8
0
        /// <summary>
        /// 输出所有的文档
        /// </summary>
        public void WriteAllDocument()
        {
            DomDocument mainDocument = this.MainDocument;

            this.CollectionDocumentsStyle();
            this.WriteStartDocument(mainDocument);
            if (this.OutputHeaderFooter)
            {
                XPageSettings ps = mainDocument.PageSettings;
                if (ps.HeaderDistance > 0 && mainDocument.Header.HasContentElement)
                {
                    this.Writer.WriteStartHeader();
                    this.ClipRectangle = new RectangleF(
                        0,
                        0,
                        mainDocument.Width,
                        mainDocument.Header.Height);
                    mainDocument.Header.WriteRTF(this);
                    this.Writer.WriteEndHeader();
                }
                if (ps.FooterDistance > 0 & mainDocument.Footer.HasContentElement)
                {
                    this.Writer.WriteStartFooter();
                    this.ClipRectangle = new RectangleF(
                        0,
                        0,
                        mainDocument.Width,
                        mainDocument.Footer.Height);
                    mainDocument.Footer.WriteRTF(this);
                    this.Writer.WriteEndFooter();
                }
            }
            foreach (DomDocument doc in this.Documents)
            {
                this.bolFirstParagraph = true;
                doc.Body.WriteRTF(this);
            }
            this.WriteEndDocument();
        }
예제 #9
0
        /// <summary>
        /// 从RTF文档生成文本文档内容对象
        /// </summary>
        /// <param name="document">文本文档对象</param>
        /// <returns>包含生成的内容对象的列表</returns>
        public void ReadContent(DomDocument document)
        {
            document.Clear();
            if (this.EnableDocumentSetting)
            {
                XPageSettings ps = new XPageSettings();
                ps.Landscape  = _RTFDocument.Landscape;
                ps.LeftMargin = GraphicsUnitConvert.FromTwips(
                    _RTFDocument.LeftMargin, GraphicsUnit.Document) / 3;
                ps.TopMargin = GraphicsUnitConvert.FromTwips(
                    _RTFDocument.TopMargin, GraphicsUnit.Document) / 3;
                ps.RightMargin = GraphicsUnitConvert.FromTwips(
                    _RTFDocument.RightMargin, GraphicsUnit.Document) / 3;
                ps.BottomMargin = GraphicsUnitConvert.FromTwips(
                    _RTFDocument.BottomMargin, GraphicsUnit.Document) / 3;
                ps.PaperWidth = GraphicsUnitConvert.FromTwips(
                    _RTFDocument.PaperWidth, GraphicsUnit.Document) / 3;
                ps.PaperHeight = GraphicsUnitConvert.FromTwips(
                    _RTFDocument.PaperHeight, GraphicsUnit.Document) / 3;
                document.PageSettings = ps;

                document.Info.Title            = _RTFDocument.Info.Title;
                document.Info.Author           = _RTFDocument.Info.Author;
                document.Info.CreationTime     = _RTFDocument.Info.Creatim;
                document.Info.Description      = _RTFDocument.Info.Comment;
                document.Info.LastPrintTime    = _RTFDocument.Info.Printim;
                document.Info.LastModifiedTime = _RTFDocument.Info.Revtim;
                document.Info.EditMinute       = _RTFDocument.Info.edmins;
            }
            document.Elements.Clear();
            document.Initializing = true;
            ReadContent(
                _RTFDocument,
                document,
                document.Elements,
                new DocumentFormatInfo());
            document.Initializing = false;
            document.AfterLoad(FileFormat.RTF);
        }
예제 #10
0
        /// <summary>
        /// 从m_Appcfg表中捞取病历预览的页面配置的Xml
        /// </summary>
        private void InitEmrPageSetting()
        {
            try
            {
                string xmldoc = BasicSettings.GetStringConfig("PageSettingPreView");
                System.Xml.XmlDocument doc = new XmlDocument();
                doc.LoadXml(xmldoc);
                XmlNode pagesetting = doc.ChildNodes[0].SelectSingleNode("pagesettings");
                if (pagesetting != null)
                {
                    XmlElement    ele = (pagesetting as XmlElement).SelectSingleNode("page") as XmlElement;
                    XPageSettings ps  = new XPageSettings();
                    ps.PaperSize.Kind = (PaperKind)Enum.Parse(typeof(PaperKind), ele.GetAttribute("kind"));
                    if (ps.PaperSize.Kind == PaperKind.Custom)
                    {
                        ps.PaperSize.Height = int.Parse(ele.GetAttribute("height"));
                        ps.PaperSize.Width  = int.Parse(ele.GetAttribute("width"));
                    }
                    ele               = (pagesetting as XmlElement).SelectSingleNode("margins") as XmlElement;
                    ps.Margins.Left   = int.Parse(ele.GetAttribute("left"));
                    ps.Margins.Right  = int.Parse(ele.GetAttribute("right"));
                    ps.Margins.Top    = int.Parse(ele.GetAttribute("top"));
                    ps.Margins.Bottom = int.Parse(ele.GetAttribute("bottom"));

                    ele             = (pagesetting as XmlElement).SelectSingleNode("landscape") as XmlElement;
                    ps.Landscape    = bool.Parse(ele.GetAttribute("value"));
                    ele             = (pagesetting as XmlElement).SelectSingleNode("header") as XmlElement;
                    ps.HeaderHeight = int.Parse(ele.GetAttribute("height"));
                    ele             = (pagesetting as XmlElement).SelectSingleNode("footer") as XmlElement;
                    ps.FooterHeight = int.Parse(ele.GetAttribute("height"));
                    this.m_EditorForm.CurrentEditorControl.EMRDoc.Pages.PageSettings = ps;
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
예제 #11
0
        /// <summary>
        /// 设置Pagesize是否可用
        /// </summary>
        private void setPagerSize(PaperKind kind)
        {
            this.txtWidth.Enabled  = (kind == System.Drawing.Printing.PaperKind.Custom);
            this.txtHeight.Enabled = (kind == System.Drawing.Printing.PaperKind.Custom);
            if (kind == System.Drawing.Printing.PaperKind.Custom)
            {
                decimal width  = Convert.ToDecimal(MeasureConvert.HundredthsInchToMillimeter(myPageSettings.PaperWidth));
                decimal height = Convert.ToDecimal(MeasureConvert.HundredthsInchToMillimeter(myPageSettings.PaperHeight));

                if (width < this.txtWidth.Minimum)
                {
                    this.txtWidth.Value = this.txtWidth.Minimum;
                }
                else
                {
                    this.txtWidth.Value = width;
                }

                if (height < this.txtHeight.Minimum)
                {
                    this.txtHeight.Value = this.txtHeight.Minimum;
                }
                else
                {
                    this.txtHeight.Value = height;
                }
            }
            else
            {
                Size size = XPageSettings.GetStandardPaperSize(kind);
                if (size.IsEmpty == false)
                {
                    this.txtWidth.Value  = Convert.ToDecimal(MeasureConvert.HundredthsInchToMillimeter(size.Width));
                    this.txtHeight.Value = Convert.ToDecimal(MeasureConvert.HundredthsInchToMillimeter(size.Height));
                }
            }
        }
예제 #12
0
        /// <summary>
        /// 打印指定页面
        /// </summary>
        /// <param name="myPage">页面对象</param>
        /// <param name="g">绘图操作对象</param>
        /// <param name="MainClipRect">主剪切矩形</param>
        /// <param name="UseMargin">是否启用页边距</param>
        public override void DrawPage(
            PrintPage myPage,
            System.Drawing.Graphics g,
            System.Drawing.Rectangle MainClipRect,
            bool UseMargin)
        {
            //XPageSettings pageSettings = myPage.PageSettings;
            int LeftMargin   = 0;
            int TopMargin    = 0;
            int RightMargin  = 0;
            int BottomMargin = 0;

            if (UseMargin)
            {
                LeftMargin   = (int)myPage.ViewLeftMargin;
                TopMargin    = (int)myPage.ViewTopMargin;
                RightMargin  = (int)myPage.ViewRightMargin;
                BottomMargin = (int)myPage.ViewBottomMargin;
            }

            this.OnBeforeDrawPage(myPage, g);
            IntPtr          hdc = g.GetHdc();
            DeviceCapsClass dcc = new DeviceCapsClass(hdc);

            g.ReleaseHdc();

            DomDocument   document = (DomDocument)this.Document;
            XPageSettings ps       = myPage.PageSettings;

            if (ps == null)
            {
                ps = document.PageSettings;
            }
            g.PageUnit = document.DocumentGraphicsUnit;
            System.Drawing.Rectangle ClipRect = System.Drawing.Rectangle.Empty;
            if (this.PageHeadText != null)
            {
                // 绘制标题文本
                g.DrawString(
                    this.PageHeadText,
                    System.Windows.Forms.Control.DefaultFont,
                    System.Drawing.Brushes.Red,
                    20,
                    20,
                    System.Drawing.StringFormat.GenericDefault);
            }
            float printableAreaOffsetX = (float)GraphicsUnitConvert.Convert(
                this.PrintableAreaOffset.X / 100.0,
                System.Drawing.GraphicsUnit.Inch,
                document.DocumentGraphicsUnit);
            float printableAreaOffsetY = (float)GraphicsUnitConvert.Convert(
                this.PrintableAreaOffset.Y / 100.0,
                System.Drawing.GraphicsUnit.Inch,
                document.DocumentGraphicsUnit);

            float headerHeight    = Math.Max(ps.ViewHeaderHeight, document.Header.Height);
            int   headerHeightFix = 0;

            if (document.Header.Height > ps.ViewHeaderHeight - 10)
            {
                headerHeightFix = ( int )(document.Header.Height - (ps.ViewHeaderHeight - 10));
            }
            if (this.DrawHead)
            {
                // 绘制页眉
                g.ResetTransform();
                g.ResetClip();
                ClipRect = new System.Drawing.Rectangle(
                    0,
                    0,
                    myPage.Width,
                    (int)headerHeight);

                g.ScaleTransform(this.XZoomRate, this.YZoomRate);
                g.TranslateTransform(
                    LeftMargin - printableAreaOffsetX,
                    ps.ViewHeaderDistance - printableAreaOffsetY);

                g.SetClip(new System.Drawing.Rectangle(
                              ClipRect.Left,
                              ClipRect.Top,
                              ClipRect.Width + 1,
                              ClipRect.Height + 1));

                PageDocumentPaintEventArgs args = new PageDocumentPaintEventArgs(
                    g,
                    ClipRect,
                    document,
                    myPage,
                    PageContentPartyStyle.Header);
                args.RenderMode    = ContentRenderMode.Print;
                args.ContentBounds = ClipRect;
                document.DrawContent(args);
                //DesignPaintEventArgs e = new DesignPaintEventArgs( g , ClipRect );
                //myDocument.RefreshView( e );
                g.ResetClip();
                g.ResetTransform();
            }

            // 绘制页面正文
            ClipRect = new System.Drawing.Rectangle(
                0,
                myPage.Top,
                myPage.Width,
                myPage.Height);

            if (!MainClipRect.IsEmpty)
            {
                ClipRect = System.Drawing.Rectangle.Intersect(ClipRect, MainClipRect);
            }
            if (!ClipRect.IsEmpty)
            {
                g.ScaleTransform(this.XZoomRate, this.YZoomRate);
                g.TranslateTransform(
                    LeftMargin - printableAreaOffsetX,
                    TopMargin - myPage.Top + headerHeightFix - printableAreaOffsetY);

                //System.Drawing.Drawing2D.GraphicsPath clipPath = new System.Drawing.Drawing2D.GraphicsPath();
                //clipPath.AddRectangle( ClipRect );
                //g.SetClip( clipPath );

                //g.TranslateTransform( myPages.LeftMargin , myPages.TopMargin - myPage.Top + myPages.HeadHeight );

                System.Drawing.RectangleF rect = DrawerUtil.FixClipBounds(
                    g,
                    ClipRect.Left,
                    ClipRect.Top,
                    ClipRect.Width,
                    ClipRect.Height);

                rect.Offset(-4, -4);
                rect.Width  = rect.Width + 8;
                rect.Height = rect.Height + 8;
                g.SetClip(rect);

                //				System.Drawing.RectangleF rect2 = g.ClipBounds ;
                //				if( rect.Top < rect2.Top )
                //				{
                //					float dy = rect2.Top - rect.Top ;
                //					rect.Y = rect.Y - dy * 2 ;
                //					rect.Height = rect.Height + dy * 4 ;
                //				}
                //				g.SetClip( rect );

                PageDocumentPaintEventArgs args = new PageDocumentPaintEventArgs(
                    g,
                    ClipRect,
                    document,
                    myPage,
                    PageContentPartyStyle.Body);
                args.RenderMode    = ContentRenderMode.Print;
                args.ContentBounds = ClipRect;
                document.DrawContent(args);

                //myDocument.DrawDocument( g , ClipRect );
                //DesignPaintEventArgs e = new DesignPaintEventArgs( g , ClipRect );
                //myDocument.RefreshView( e );
            }

            if (this.DrawFooter)
            {
                // 绘制页脚
                g.ResetClip();
                g.ResetTransform();
                int   documentHeight = myPage.DocumentHeight;
                float footerHeight   = Math.Max(document.Footer.Height, ps.ViewFooterHeight);
                ClipRect = new System.Drawing.Rectangle(
                    0,
                    0,
                    myPage.Width,
                    (int)footerHeight);
                int dy = 0;

                dy = (int)(myPage.ViewPaperHeight
                           - ps.ViewFooterDistance - document.Footer.Height);

                g.ScaleTransform(this.XZoomRate, this.YZoomRate);
                g.TranslateTransform(
                    LeftMargin - printableAreaOffsetX,
                    dy - printableAreaOffsetY);

                g.SetClip(new System.Drawing.Rectangle(
                              ClipRect.Left,
                              ClipRect.Top,
                              ClipRect.Width + 1,
                              ClipRect.Height + 1));

                PageDocumentPaintEventArgs args = new PageDocumentPaintEventArgs(
                    g,
                    ClipRect,
                    document,
                    myPage,
                    PageContentPartyStyle.Footer);
                args.RenderMode    = ContentRenderMode.Print;
                args.ContentBounds = ClipRect;
                document.DrawContent(args);
                //DesignPaintEventArgs e = new DesignPaintEventArgs( g , ClipRect );
                //myDocument.RefreshView( e );
            } //if( this.bolDrawFooter )
        }     //public void DrawPage()
예제 #13
0
        /// <summary>
        /// 根据页面位置添加矩形区域转换关系
        /// </summary>
        /// <param name="myTransform">转换列表</param>
        /// <param name="ForPrint">是否为打印进行填充</param>
        public override void AddPage(PrintPage page, float pageTop, float zoomRate)
        {
            //XPageSettings pageSettings = page.PageSettings;
            XPageSettings ps = page.PageSettings;

            System.Drawing.Rectangle rect = System.Drawing.Rectangle.Empty;

            int leftmargin   = (int)(page.ViewLeftMargin * zoomRate);
            int topmargin    = (int)(page.ViewTopMargin * zoomRate);
            int rightmargin  = (int)(page.ViewRightMargin * zoomRate);
            int bottommargin = (int)(page.ViewBottomMargin * zoomRate);
            int pagewidth    = (int)(page.ViewPaperWidth * zoomRate);
            int pageheight   = (int)(page.ViewPaperHeight * zoomRate);

            int top = (int)pageTop + topmargin;

            SimpleRectangleTransform headerItem = null;
            SimpleRectangleTransform bodyItem   = null;
            SimpleRectangleTransform footerItem = null;
            DomDocument document = (DomDocument)page.Document;

            // 添加文档页眉视图映射
            headerItem                = new SimpleRectangleTransform();
            headerItem.Enable         = (document.CurrentContentPartyStyle == PageContentPartyStyle.Header);
            headerItem.PageIndex      = page.PageIndex;
            headerItem.ContentStyle   = PageContentPartyStyle.Header;
            headerItem.PageObject     = page;
            headerItem.DocumentObject = page.Document;
            // 映射到文档视图
            //if (document.CurrentContentElement == document.Header)
            {
                headerItem.DescRectF = new System.Drawing.RectangleF(
                    0,
                    0,
                    page.Width,
                    // 如果当前编辑区域是页眉则设置页眉可视区域的高度为页眉内容高度和页眉标准高度的较大者
                    Math.Max(ps.ViewHeaderHeight - 1, document.Header.Height));
            }
            if (document.Header.Height > ps.ViewHeaderHeight)
            {
                top = top + (int)((document.Header.Height - ps.ViewHeaderHeight) * zoomRate);
            }
            //else
            //{
            //    headerItem.DescRectF = new System.Drawing.RectangleF(
            //        0,
            //        0,
            //        page.Width,
            //        page.ViewTopMargin - ps.ViewHeaderDistance - 1);
            //}
            SetSourceRect(
                headerItem,
                zoomRate,
                leftmargin + page.ClientLeftFix,
                (int)(pageTop + ps.ViewHeaderDistance * zoomRate));
            headerItem.PartialAreaSourceBounds = new Rectangle(
                headerItem.SourceRect.Left,
                headerItem.SourceRect.Top,
                headerItem.SourceRect.Width,
                headerItem.SourceRect.Height);
            //(int)( headerItem.DescRectF.Height * zoomRate ));


            // 添加正文文档映射
            bodyItem                = new SimpleRectangleTransform();
            bodyItem.Enable         = (document.CurrentContentPartyStyle == PageContentPartyStyle.Body);
            bodyItem.PageIndex      = page.PageIndex;
            bodyItem.ContentStyle   = PageContentPartyStyle.Body;
            bodyItem.PageObject     = page;
            bodyItem.DocumentObject = page.Document;
            // 映射到文档视图
            bodyItem.DescRectF = new System.Drawing.RectangleF(
                0,
                page.Top,
                page.Width,
                page.Height);
            int spacing = 0;

            if (document.Header.Height > ps.ViewHeaderHeight - 10)
            {
                spacing = 5;// 当页眉实际高度大于标准页眉高度,页眉内容突出了标准区域,此时为了美观,页眉和页身之间留点空隙
            }
            top = SetSourceRect(
                bodyItem,
                zoomRate,
                leftmargin + page.ClientLeftFix,
                headerItem.PartialAreaSourceBounds.Bottom + spacing);

            bodyItem.PartialAreaSourceBounds = new Rectangle(
                bodyItem.SourceRect.Left,
                bodyItem.SourceRect.Top,
                bodyItem.SourceRect.Width,
                (int)(document.GetStandartPapeViewHeight(ps) * zoomRate));


            // 添加页脚文档视图映射
            footerItem                = new SimpleRectangleTransform();
            footerItem.Enable         = (document.CurrentContentPartyStyle == PageContentPartyStyle.Footer);
            footerItem.PageIndex      = page.PageIndex;
            footerItem.ContentStyle   = PageContentPartyStyle.Footer;
            footerItem.PageObject     = page;
            footerItem.DocumentObject = page.Document;
            // 映射到文档视图
            //if (document.CurrentContentElement == document.Footer)
            {
                footerItem.DescRectF = new System.Drawing.RectangleF(
                    0,
                    0,
                    page.Width,
                    // 如果当前编辑区域是页脚则设置页脚可视区域的高度为页脚内容高度和页脚标准高度的较大者
                    document.Footer.Height);
            }
            //else
            //{
            //    footerItem.DescRectF = new System.Drawing.RectangleF(
            //        0,
            //        0,
            //        page.Width,
            //        page.ViewBottomMargin - ps.ViewFooterDistance - 1);
            //}
            SetSourceRect(
                footerItem,
                zoomRate,
                leftmargin + page.ClientLeftFix,
                ( int )(pageTop + pageheight - ps.ViewFooterDistance * zoomRate - document.Footer.Height * zoomRate));
            //bodyItem.PartialAreaSourceBounds.Bottom + 2);// 为了美观,页身和页脚之间留点空隙,由于页身实际高度经常小于页身标准高度,因此留的空隙小一些。

            footerItem.PartialAreaSourceBounds = new Rectangle(
                footerItem.SourceRect.Left,
                (int )(pageTop + pageheight - bottommargin),
                footerItem.SourceRect.Width,
                ( int )(footerItem.SourceRect.Bottom - (pageTop + pageheight - bottommargin)));   // footerItem.SourceRect.Height );
            //(int)( footerItem.DescRectF.Height * zoomRate));


            switch (document.CurrentContentPartyStyle)
            {
            case PageContentPartyStyle.Header:
                if (headerItem != null)
                {
                    this.Add(headerItem);
                }
                this.Add(bodyItem);
                if (footerItem != null)
                {
                    this.Add(footerItem);
                }
                break;

            case PageContentPartyStyle.Body:
                this.Add(bodyItem);
                if (headerItem != null)
                {
                    this.Add(headerItem);
                }
                if (footerItem != null)
                {
                    this.Add(footerItem);
                }
                break;

            case PageContentPartyStyle.Footer:
                if (footerItem != null)
                {
                    this.Add(footerItem);
                }
                if (headerItem != null)
                {
                    this.Add(headerItem);
                }
                this.Add(bodyItem);
                break;
            }//switch
        }
예제 #14
0
        /// <summary>
        /// 已重载:查询页面设置
        /// </summary>
        /// <param name="e">事件参数</param>
        protected override void OnQueryPageSettings(System.Drawing.Printing.QueryPageSettingsEventArgs e)
        {
            base.OnQueryPageSettings(e);
            if (CheckContent())
            {
                //string printerNameBack = this.CurrentPrintPage.PageSettings.PrinterName;

                //this.CurrentPrintPage.PageSettings.PrinterName =
                //    e.PageSettings.PrinterSettings.PrinterName;

                XPageSettings ps = this.CurrentPrintingPage.PageSettings.Clone();
                ps.PrinterName = e.PageSettings.PrinterSettings.PrinterName;

                // 指定打印机
                string printerName = ps.PrinterName;
                if (printerName != null && printerName.Trim().Length > 0)
                {
                    printerName = printerName.Trim();
                    foreach (string name in PrinterSettings.InstalledPrinters)
                    {
                        if (string.Compare(printerName, name, true) == 0)
                        {
                            //this.PrinterSettings.PrinterName = name;
                            e.PageSettings.PrinterSettings.PrinterName = name;
                            base.PrinterSettings.PrinterName           = name;
                            break;
                        }
                    }
                }

                // 指定纸张设置
                string paperSource = ps.PaperSource;
                if (paperSource != null && paperSource.Trim().Length > 0)
                {
                    foreach (System.Drawing.Printing.PaperSource source
                             in e.PageSettings.PrinterSettings.PaperSources)
                    {
                        if (string.Compare(source.SourceName, paperSource, true) == 0)
                        {
                            e.PageSettings.PaperSource = source;
                            break;
                        }
                    }
                    //e.PageSettings.PaperSource.SourceName = paperSource;
                }

                //if (ps.StickToPageSize)
                //{
                if (ps.PaperKind == PaperKind.Custom)
                {
                    System.Drawing.Printing.PaperSize newSize = new PaperSize("Custom", ps.PaperWidth, ps.PaperHeight);
                    //System.Drawing.Printing.PaperSize newSize = new PaperSize( mySize.PaperName, ps.PaperWidth, ps.PaperHeight);
                    newSize.Width  = ps.PaperWidth;
                    newSize.Height = ps.PaperHeight;
                    //newSize.RawKind = mySize.RawKind;
                    e.PageSettings.PaperSize = newSize;
                }
                //if (ps.PaperKind != PaperKind.Custom)
                else
                {
                    foreach (System.Drawing.Printing.PaperSize mySize
                             in e.PageSettings.PrinterSettings.PaperSizes)
                    {
                        if (ps.PaperKind == mySize.Kind)
                        {
                            e.PageSettings.PaperSize = mySize;
                            break;
                        }
                    }
                }
                //}
                e.PageSettings.Margins   = ps.Margins;
                e.PageSettings.Landscape = ps.Landscape;
            }
        }
예제 #15
0
        private void simpleButtonPageSetting_Click(object sender, EventArgs e)
        {
            XPageSettings PageSettings = new XPageSettings();

            CurrentForm.zyEditorControl1.EMRDoc._PageSetting(ref PageSettings);
        }