i have a Image loaded in c# and i would like to print it in the size of 269 x 148 mm to a DIN A4 page in landscape exactly in the middle. When i print it via PDF Printer in a file, it works perfect. But when i print it with my Default Printer, the left marge is a Little bit thicker as the right marge.
Here´s my Code:
private void PrintImage(Image img) {
PrintDocument pd = new PrintDocument();
//Disable the printing document pop-up dialog shown during printing.
PrintController printController = new StandardPrintController();
pd.PrintController = printController;
pd.DefaultPageSettings.Landscape = true;
pd.OriginAtMargins = false;
pd.PrintPage += (sndr, args) => {
System.Drawing.Image i = img;
//Adjust the size of the image to the page to print the full image without loosing any part of the image.
System.Drawing.Rectangle m = args.MarginBounds;
Rectangle t = args.MarginBounds;
//PrintDialog myPrintDialog1 = new PrintDialog();
//Logic below maintains Aspect Ratio.
double cmToUnits = 100 / 2.54;
m.Width = (Int32)(width * cmToUnits);
m.Height = (Int32)(height * cmToUnits);
pd.DefaultPageSettings.Landscape = true;
//Putting image in center of page.
m.Y = (int)((((System.Drawing.Printing.PrintDocument)(sndr)).DefaultPageSettings.PaperSize.Width - m.Height) / 2);
m.X = (int)((((System.Drawing.Printing.PrintDocument)(sndr)).DefaultPageSettings.PaperSize.Height - m.Width) / 2);
args.Graphics.DrawImage(i, m);
};
PrintDialog myPrintDialog1 = new PrintDialog();
myPrintDialog1.Document = pd;
if (myPrintDialog1.ShowDialog() == DialogResult.OK){
pd.Print();
}
}