日期:2014-05-17  浏览次数:21404 次

PrintDocument打印预览正常,打印时错位的问题
在网上查了很多资料,好像是打印机物理边距的问题..但是没有找到解决方法..请大帮帮忙


------解决方案--------------------
下面的代码是自己设定边距的,详细说明参考http://bingning.net/free/source/graphics/pagesetupdialogbug.html
C# code

PageSetupDialog PageSetupDialog1 = new PageSetupDialog();
 PageSetupDialog1.Document =
     new System.Drawing.Printing.PrintDocument();
 //指定Margin
 PageSetupDialog1.PageSettings.Margins =
     new System.Drawing.Printing.Margins(100, 100, 100, 100);
 
 if (System.Globalization.RegionInfo.CurrentRegion.IsMetric)
 {
     PageSetupDialog1.PageSettings.Margins.Top =
         (int)Math.Round(
         PageSetupDialog1.PageSettings.Margins.Top * 2.54);
     PageSetupDialog1.PageSettings.Margins.Bottom =
         (int)Math.Round(
         PageSetupDialog1.PageSettings.Margins.Bottom * 2.54);
     PageSetupDialog1.PageSettings.Margins.Left =
         (int)Math.Round(
         PageSetupDialog1.PageSettings.Margins.Left * 2.54);
     PageSetupDialog1.PageSettings.Margins.Right =
         (int)Math.Round(
         PageSetupDialog1.PageSettings.Margins.Right * 2.54);
 }
 
 //表示页面设置窗体
 if (PageSetupDialog1.ShowDialog() == DialogResult.OK)
     Console.WriteLine(PageSetupDialog1.PageSettings.Margins);
 else if (System.Globalization.RegionInfo.CurrentRegion.IsMetric)
 {
     //返回原设置
     PageSetupDialog1.PageSettings.Margins.Top =
         (int)Math.Round(
         PageSetupDialog1.PageSettings.Margins.Top / 2.54);
     PageSetupDialog1.PageSettings.Margins.Bottom =
         (int)Math.Round(
         PageSetupDialog1.PageSettings.Margins.Bottom / 2.54);
     PageSetupDialog1.PageSettings.Margins.Left =
         (int)Math.Round(
         PageSetupDialog1.PageSettings.Margins.Left / 2.54);
     PageSetupDialog1.PageSettings.Margins.Right =
         (int)Math.Round(
         PageSetupDialog1.PageSettings.Margins.Right / 2.54);
 }

------解决方案--------------------
UP