我遇到同样的需求。以下是为我提供所需功能的一些逻辑:
//
// PrintDocument_inst
//
this.PrintDocument_inst.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.k_line_PrintPage);
private void Print(string align_file_name)
{
if (plot_metafile == null)
{
MessageBox.Show("you need to load offset data before printing a plot");
return;
}
try
{
PrintDocument_inst.DefaultPageSettings = PageSettings_inst;
PrintDialog_inst = new PrintDialog();
PrintDialog_inst.Document = PrintDocument_inst;
PrintDialog_inst.UseEXDialog = true; // this must be set true or dialog won't show on 64 bit Vista
PrintDialog_inst.PrinterSettings.PrinterName = "Microsoft XPS Document Writer";
PrintDialog_inst.PrinterSettings.PrintToFile = true;
PrintDialog_inst.PrinterSettings.PrintFileName = align_file_name;
i_page_to_print_next = 1;
n_pages_still_to_print = 1;
PrintDocument_inst.Print();
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
finally
{
}
} // end of function Print(string align_file_name)
//PrintPage event handler
private void k_line_PrintPage(object sender,PrintPageEventArgs ppea)
{
int leftMargin = ppea.MarginBounds.Left;
int topMargin = ppea.MarginBounds.Top ;
try
{
float _scale_f;
if (PrintDialog_inst != null)
{
string str_printer_name = PrintDialog_inst.PrinterSettings.PrinterName.ToString ();
if (str_printer_name.CompareTo ("Adobe PDF") == 0)
{
_scale_f = 0.61F; // 0.85F;
}
else
{
_scale_f = 0.59F; // 0.82F;
}
}
else // case of print preview
{
_scale_f = 0.59F; // 0.82F;
}
if (_scale_f != 1.0F) ppea.Graphics.ScaleTransform (_scale_f, _scale_f);
ppea.Graphics.DrawImage (plot_metafile, leftMargin, topMargin);
ppea.HasMorePages = (--n_pages_still_to_print > 0 ? true : false);
}
finally
{
}
} // end of private void k_line_PrintPage(object sender,PrintPageEventArgs ppea)
你能澄清一下这个问题吗?你在用什么语言工作?您是否专门尝试从您的应用程序创建XPS输出,还是仅仅当XPS Document Writer是默认驱动程序时,弹出对话框会干扰应该是自动化工作流的内容? – Jon 2011-03-03 20:05:21
也许您已阅读的某些链接,如果您提供这些链接以帮助您解决问题,可能会有所帮助。 – Nocturnal 2011-03-04 08:25:19
乔恩 - 问题是关于创建一个打印机驱动程序。这是一个打印到计算机默认打印机的自动化过程。 - 夜间,谢谢,但实际上我离开了这个解决方案,并购买了第三方产品。 – 2011-04-06 08:09:11