简体   繁体   中英

Issue printing image as expected

I have an image that I'm trying to print to legal size. However, there are a few challenges to this.

  1. The image will vary in size. This is because I'm using a control that has limited print options but can export to an image.
  2. I want to maximize the print area on the page. Smallest margin possible
  3. The user needs to be able to select a printer and set options

Here's the code I'm using:

 PrintDocument pd = new PrintDocument();
            pd.PrintPage += (sender, args) =>
            {
                Image i = Image.FromFile(Globals.TempDirectory + @"\temp.jpg");
                Point p = new Point(100, 100);
                Margins margins = new Margins(50, 50, 50, 50);
                pd.DefaultPageSettings.Margins = margins;
                args.Graphics.DrawImage(i, p);
            };
            pd.Print();

I've been having trouble with this because I can't set margins and can't seem to get the print out right. I want it to print in legal but when I print the image, it's not rotated properly and it just prints to a default printer. I'm up for anything to get this to work.

Printing in C# sucks

try a

printdialog() 

to allow the user to select a printer and settings. once you get that to work the rest of it might click for you.

Edit: Showing you where and how to use it.

PrintDialog pDialog = new PrintDialog();
if (pDialog.ShowDialog() == DialogResult.OK)
{
   pd.PrinterSettings = pDialog.PrinterSettings;
   pd.Print();
}

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