簡體   English   中英

相同的C#Windows Form應用程序從不同的打印機獲得不同的打印尺寸

[英]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)

因此,您要做的就是獲取HardMarginXHardMarginY ,進行一些數學運算並在要打印的位置進行打印。

還有一件事,如果您嘗試在這些邊距之外打印,則文檔可能會被剪切。 在Internet上搜索打印機的PrintableArea ,您便會明白。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM