Emita la imagen de impresión como se esperaba

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

Aquí está el código que estoy usando:

 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.

preguntado el 22 de mayo de 12 a las 14:05

1 Respuestas

Printing in C# sucks

prueba un

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();
}

contestado el 22 de mayo de 12 a las 15:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.