简体   繁体   English

相同的C#Windows Form应用程序从不同的打印机获得不同的打印尺寸

[英]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. 因此,您要做的就是获取HardMarginXHardMarginY ,进行一些数学运算并在要打印的位置进行打印。

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.

相关问题 vsto:使用C#在相同的解决方案中从Windows窗体应用程序迁移不同的excel工作簿 - vsto: Caling different excel workbooks from windows form application in same solutions using c# 如何在C#窗体应用程序的另一个(不同的)页面上打印列出的发票? - How to Print Listed invoices each on another (different) Page in C# windows form Application? 我如何从C#中同一项目下的不同Windows窗体访问不同的组件? - How can i access the different component from different windows form which are under same project in c#? Windows窗体应用程序C#将文本传播到不同的文本框 - Windows form application c# spread text into different Textboxes 如何检查不同picBox中的图片是否相同? C#Windows窗体 - How to check if pictures in different picBoxes are the same? c# windows form 为什么Windows窗体大小与C#中的设置不同? - Why is the windows form size different from its setting in C#? C# Windows 窗体应用程序:如何使用循环将 5 个不同的数据放在 5 个不同的标签中 - C# Windows Form Application: How to put 5 different data in 5 different labels using a loop C#从不同的网址打开同一应用程序并传递参数 - C# Open Same Application From Different Url and pass parameters 不同Windows形式的C#类的对象 - C# object of class in different windows form 在Windows应用程序C#中以不同语言打印输出 - printout in different languages in windows application c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM