【问题标题】:Silently use Microsoft XPS Document Writer printer to create XPS静默使用 Microsoft XPS Document Writer 打印机创建 XPS
【发布时间】:2011-07-08 03:35:57
【问题描述】:

几天来,我一直在努力在没有对话框的情况下将 XPS 打印到文件中。 我已经阅读了 CodeGuru 和 Feng Yuan (MSDN) 中关于此事的帖子,以及这里的许多讨论主题,但我仍然迷路了。

具体来说,我的情况是我必须使用第 3 方 API,它会打印到默认打印机(例如 Microsoft XPS Document Writer)。我希望能够在打印过程之前“应用”一个文件名,当然不要有对话框。

我尝试过使用 WinDDK - XPSDRV 和 LOCALMON 示例,但无法准确弄清楚如何操作代码以实现我的目标。 (甚至完全了解我是否需要新的打印机驱动程序或新的端口类型)

【问题讨论】:

  • 你能稍微澄清一下这个问题吗?你用什么语言工作?您是专门尝试从您的应用程序创建 XPS 输出,还是只是当 XPS Document Writer 是默认驱动程序时,弹出对话框干扰了应该是自动化的工作流程?
  • 也许您已经阅读了一些链接,如果您提供它们来帮助您解决问题,可能会有所帮助。
  • Jon - 问题是关于创建打印机驱动程序。这是一个自动打印到计算机默认打印机的过程。 - 夜间,谢谢,但事实上我离开了这个解决方案并购买了第 3 方产品。

标签: windows printing xps wdk


【解决方案1】:

我遇到了同样的需求。以下是为我提供所需功能的一些逻辑:

 // 
 // 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)

【讨论】:

    【解决方案2】:

    您将删除管道 xml 中的过滤器以及 inf 文件中的相关 dll。但是,正如我所做的那样,我想您将面临打印画布(图形)的问题。我无法将此画布转换/转换为字形以获取其内容。

    如果您还有其他问题,请告诉我

    亲切的问候

    【讨论】:

      猜你喜欢
      • 2016-09-08
      • 2012-10-15
      • 2011-01-18
      • 2011-09-21
      • 1970-01-01
      • 2011-11-27
      • 1970-01-01
      • 1970-01-01
      • 2019-09-22
      相关资源
      最近更新 更多