![](/img/trans.png)
[英]vsto: Caling different excel workbooks from windows form application in same solutions using c#
[英]Different print dimensions from different printers by same C# Windows Form Application
相同的C#应用程序通过不同的打印机以不同的尺寸打印文本。 打印的文字在x轴上相同,但在y轴上不同。 我的意思是,在一种打印中,文本比其他打印稍向上(4-5mm),但沿x轴方向相同,即没有文本比其他打印要向后或向前。 例如:
“此文本在x轴上相同,但在y轴上不同”(打印1)
“此文本在x轴上相同,但在y轴上不同”(打印2)
我的页面设置为:
private void PaperSettings()
{
PaperSize paperSize = new PaperSize("New Page", 377, 1095);
paperSize.RawKind = (int)PaperKind.Custom;
printDocument1.DefaultPageSettings.PaperSize = paperSize;
Margins margin = new Margins(0, 0, 0, 0);
printDocument1.DefaultPageSettings.Margins = margin;
printDocument1.DefaultPageSettings.Landscape = true;
PrinterSettings printer = new PrinterSettings();
printDocument1.PrinterSettings.PrinterName = printer.PrinterName;
}
手动更改纸张宽度(377)时,文本在增加时向上移动,在减小时向下移动。 但是,相同的页面设置在不同的打印机上不起作用* (HP Officejet J3500打印的文字比HP Deskjet 1510打印的文字略低)。*
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawString(label1Payee.Text, label1Payee.Font, Brushes.Black, label1Payee.Location.X, label1Payee.Location.Y);
e.Graphics.DrawString(labelAmountWords.Text, labelAmountWords.Font, Brushes.Black, labelAmountWords.Location.X, labelAmountWords.Location.Y);
e.Graphics.DrawString(labelDate1.Text, labelDate1.Font, Brushes.Black, labelDate1.Location.X, labelDate1.Location.Y);
e.Graphics.DrawString(labelAmount.Text, labelAmount.Font, Brushes.Black, labelAmount.Location.X, labelAmount.Location.Y);
}
有什么建议么..
谢谢!
每台打印机都有一些无法打印的边距。 这些边距称为打印机的HardMargins
。 假设您要在坐标(0, 0)
上打印某些内容(0, 0)
但我的打印机在(16, 16)
上打印它。 这(HardMarginX, HardMarginY)
。
每台打印机的边距可能都不同。 例如,我的HP LaserJet 1020是(16, 16)
但我的Canon Pixma ip1300是(0, 0)
。
因此,您要做的就是获取HardMarginX
和HardMarginY
,进行一些数学运算并在要打印的位置进行打印。
还有一件事,如果您尝试在这些边距之外打印,则文档可能会被剪切。 在Internet上搜索打印机的PrintableArea
,您便会明白。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.