简体   繁体   English

按预期发行打印图像

[英]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 用C#打印很烂

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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