[英]Different print dimensions from different printers by same C# Windows Form Application
The same C# application is printing text in different dimension by different printers. 相同的C#应用程序通过不同的打印机以不同的尺寸打印文本。 The text printed is same along x-axis but differ along y-axis. 打印的文字在x轴上相同,但在y轴上不同。 I mean in one print, the text is slightly(4-5mm) upwards than other print but same along x-axis ie no text is backwards or forward than text of other print. 我的意思是,在一种打印中,文本比其他打印稍向上(4-5mm),但沿x轴方向相同,即没有文本比其他打印要向后或向前。 Eg: 例如:
"This text is same along x-axis but differ among y-axis"(Print 1) “此文本在x轴上相同,但在y轴上不同”(打印1)
"This text is same along x-axis but differ among y-axis"(Print 2) “此文本在x轴上相同,但在y轴上不同”(打印2)
My Page settings are: 我的页面设置为:
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;
}
On changing the paper width(377) manually, the text is shifted upwards on increasing it and downwards on decreasing it. 手动更改纸张宽度(377)时,文本在增加时向上移动,在减小时向下移动。 However the same page settings is not working on different printers* (HP Officejet J3500 printing text slightly downdards than text printed by HP Deskjet 1510).* 但是,相同的页面设置在不同的打印机上不起作用* (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);
}
Any Suggestions.. 有什么建议么..
Thank you! 谢谢!
Every printer has some margins where the printer does not print. 每台打印机都有一些无法打印的边距。 These margins are called printer's HardMargins
. 这些边距称为打印机的HardMargins
。 Say you want to print something on co-ordinates (0, 0)
but my printer prints it on (16, 16)
. 假设您要在坐标(0, 0)
上打印某些内容(0, 0)
但我的打印机在(16, 16)
上打印它。 This (HardMarginX, HardMarginY)
. 这(HardMarginX, HardMarginY)
。
Every printer may differ from hard margins. 每台打印机的边距可能都不同。 eg My HP LaserJet 1020 is (16, 16)
but my Canon Pixma ip1300 is (0, 0)
. 例如,我的HP LaserJet 1020是(16, 16)
但我的Canon Pixma ip1300是(0, 0)
。
So what you have to do is, get the HardMarginX
and HardMarginY
, do some math and print where you want to print. 因此,您要做的就是获取HardMarginX
和HardMarginY
,进行一些数学运算并在要打印的位置进行打印。
One more thing, if you try to print beyond these margins, document may be clipped. 还有一件事,如果您尝试在这些边距之外打印,则文档可能会被剪切。 Search for the PrintableArea
of the printer over internet and you get the idea. 在Internet上搜索打印机的PrintableArea
,您便会明白。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.