简体   繁体   中英

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. The text printed is same along x-axis but differ along y-axis. 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. Eg:

"This text is same along x-axis but differ among y-axis"(Print 1)
"This text is same along x-axis but differ among y-axis"(Print 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. 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).*

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 . Say you want to print something on co-ordinates (0, 0) but my printer prints it on (16, 16) . This (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) .

So what you have to do is, get the HardMarginX and HardMarginY , do some math and print where you want to print.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM