Ejemplo n.º 1
0
        /// <summary>
        /// 获取指定纸张尺寸的像素大小
        /// </summary>
        /// <param name="printName"></param>
        /// <param name="papaerName"></param>
        public static int[] GetPaperSize(string printName, string paperName, int defaultdpi = 300)
        {
            var pd = new PrintDocument {
                PrinterSettings = { PrinterName = printName }
            };
            var pageType = pd.DefaultPageSettings.PrinterSettings.PaperSizes;

            var type = new PaperSize[pageType.Count];

            pageType.CopyTo(type, 0);

            var paper = type.FirstOrDefault(x => x.PaperName == paperName);

            if (paper == null)
            {
                return(null);
            }
            var w = pd.DefaultPageSettings.PrinterResolution.X < 0
                ? defaultdpi * paper.Width / 100
                : pd.DefaultPageSettings.PrinterResolution.X * paper.Width / 100;
            var h = pd.DefaultPageSettings.PrinterResolution.Y < 0
                ? defaultdpi * paper.Height / 100
                : pd.DefaultPageSettings.PrinterResolution.Y * paper.Height / 100;

            return(new[] { w, h });
        }
Ejemplo n.º 2
0
        private void LoadSettings()
        {
            #region Fit
            cbA1Fit.Checked  = Properties.Settings.Default.A1Fit;
            cbA2Fit.Checked  = Properties.Settings.Default.A2Fit;
            cbA3Fit.Checked  = Properties.Settings.Default.A3Fit;
            cbA4Fit.Checked  = Properties.Settings.Default.A4Fit;
            cbA4vFit.Checked = Properties.Settings.Default.A4vFit;
            #endregion

            #region Scale
            nupA1Scale.Value  = Properties.Settings.Default.A1Scale;
            nupA2Scale.Value  = Properties.Settings.Default.A2Scale;
            nupA3Scale.Value  = Properties.Settings.Default.A3Scale;
            nupA4Scale.Value  = Properties.Settings.Default.A4Scale;
            nupA4vScale.Value = Properties.Settings.Default.A4vScale;
            #endregion

            #region Size
            foreach (string Key in PaperSize.Keys)
            {
                cbA1Size.Items.Add(Key);
                cbA2Size.Items.Add(Key);
                cbA3Size.Items.Add(Key);
                cbA4Size.Items.Add(Key);
                cbA4vSize.Items.Add(Key);
            }
            cbA1Size.Text  = PaperSize.FirstOrDefault(x => x.Value == Properties.Settings.Default.A1Size).Key;
            cbA2Size.Text  = PaperSize.FirstOrDefault(x => x.Value == Properties.Settings.Default.A2Size).Key;
            cbA3Size.Text  = PaperSize.FirstOrDefault(x => x.Value == Properties.Settings.Default.A3Size).Key;
            cbA4Size.Text  = PaperSize.FirstOrDefault(x => x.Value == Properties.Settings.Default.A4Size).Key;
            cbA4vSize.Text = PaperSize.FirstOrDefault(x => x.Value == Properties.Settings.Default.A4vSize).Key;
            #endregion

            #region Source
            foreach (string Key in PaperSource.Keys)
            {
                cbA1Source.Items.Add(Key);
                cbA2Source.Items.Add(Key);
                cbA3Source.Items.Add(Key);
                cbA4Source.Items.Add(Key);
                cbA4vSource.Items.Add(Key);
            }
            cbA1Source.Text  = PaperSource.FirstOrDefault(x => x.Value == Properties.Settings.Default.A1Source).Key;
            cbA2Source.Text  = PaperSource.FirstOrDefault(x => x.Value == Properties.Settings.Default.A2Source).Key;
            cbA3Source.Text  = PaperSource.FirstOrDefault(x => x.Value == Properties.Settings.Default.A3Source).Key;
            cbA4Source.Text  = PaperSource.FirstOrDefault(x => x.Value == Properties.Settings.Default.A4Source).Key;
            cbA4vSource.Text = PaperSource.FirstOrDefault(x => x.Value == Properties.Settings.Default.A4vSource).Key;
            #endregion
        }