Ejemplo n.º 1
0
        public static Margins PrinterMargins(PrinterSettings ps, bool Landscape)
        {
            Margins m;
            Graphics e = ps.CreateMeasurementGraphics();
            float dpiX = e.DpiX;
            float dpiY = e.DpiY;
            int offsetx, offsety;
            int horzres, vertres;
            int physicalwidth, physicalheight;

            IntPtr hDC = e.GetHdc();
            offsetx = GetDeviceCaps(hDC, PHYSICALOFFSETX);
            offsety = GetDeviceCaps(hDC, PHYSICALOFFSETY);
            horzres = GetDeviceCaps(hDC, HORZRES);
            vertres = GetDeviceCaps(hDC, VERTRES);
            physicalwidth = GetDeviceCaps(hDC, PHYSICALWIDTH);
            physicalheight = GetDeviceCaps(hDC, PHYSICALHEIGHT);
            e.ReleaseHdc(hDC);

            int left = (int)Math.Ceiling((float)offsetx * 100.0F / dpiX);
            int top = (int)Math.Ceiling((float)offsety * 100.0F / dpiY);
            int right = (int)Math.Ceiling((float)(physicalwidth - horzres - offsetx) * 100.0F / dpiX);
            int bottom = (int)Math.Ceiling((float)(physicalheight - vertres - offsety) * 100.0F / dpiY);

            if (Landscape && ps.LandscapeAngle == 90)
            {
                m = new System.Drawing.Printing.Margins(bottom, top, left, right);
            }
            else if (Landscape && ps.LandscapeAngle == 270)
            {
                m = new System.Drawing.Printing.Margins(top, bottom, right, left);
            }
            else
            {
                m = new System.Drawing.Printing.Margins(left, right, top, bottom);
            }
            return m;
        }
Ejemplo n.º 2
0
 public PrinterPrintTarget(PrinterSettings settings)
 {
     m_settings = (PrinterSettings)settings.Clone();
     m_settings.DefaultPageSettings.Landscape = false;
     m_infoDC = m_settings.CreateMeasurementGraphics();
     m_w0 = m_infoDC.VisibleClipBounds.Width;
     m_h0 = m_infoDC.VisibleClipBounds.Height;
     m_info = XGraphics.FromGraphics(m_infoDC, new XSize(m_w0, m_h0));
     m_mmkx = m_w0 / 210.0f;
     m_mmky = m_h0 / 297.0f;
 }