Exemplo n.º 1
0
 /// <summary>
 /// Replace this event when creating a custom descendant of FlexCelPrintDocument.
 /// </summary>
 /// <param name="e"></param>
 protected virtual void OnGetPrinterHardMargins(PrintHardMarginsEventArgs e)
 {
     if (GetPrinterHardMargins != null)
     {
         GetPrinterHardMargins(this, e);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// This event will adjust for a better position on the page for some printers.
        /// It is not normally necessary, and it has to make an unmanaged call to GetDeviceCaps,
        /// but it is given here as an example of how it could be done.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void flexCelPrintDocument1_GetPrinterHardMargins(object sender, FlexCel.Render.PrintHardMarginsEventArgs e)
        {
            const int PHYSICALOFFSETX = 112;
            const int PHYSICALOFFSETY = 113;

            double DpiX = e.Graphics.DpiX;
            double DpiY = e.Graphics.DpiY;

            IntPtr Hdc = e.Graphics.GetHdc();

            try
            {
                e.XMargin = (float)(GetDeviceCaps(Hdc, PHYSICALOFFSETX) * 100.0 / DpiX);
                e.YMargin = (float)(GetDeviceCaps(Hdc, PHYSICALOFFSETY) * 100.0 / DpiY);
            }

            finally
            {
                e.Graphics.ReleaseHdc(Hdc);
            }
        }
Exemplo n.º 3
0
        private RectangleF ConvertToMargins(Graphics aGraphics, Rectangle PageBounds, RectangleF VisibleRecInches100, bool Rotate90)
        {
            int w = Rotate90? PageBounds.Height: PageBounds.Width;
            int h = Rotate90? PageBounds.Width: PageBounds.Height;

            float vw = Rotate90? VisibleRecInches100.Height: VisibleRecInches100.Width;
            float vh = Rotate90? VisibleRecInches100.Width: VisibleRecInches100.Height;

            PrintHardMarginsEventArgs ex = new PrintHardMarginsEventArgs(aGraphics,
                                                                         (w - vw) / 2f,
                                                                         (h - vh) / 2f
                                                                         );

            if (ex.XMargin > 0 || ex.YMargin > 0)         //Avoid calling when preview.
            {
                OnGetPrinterHardMargins(ex);
            }

            return(new RectangleF(ex.XMargin, ex.YMargin,
                                  vw,
                                  vh));
        }