悄悄地使用微软XPS文档编写器打印机创建XPS文件。

3

最近,我一直在尝试打印 XPS 文件而不弹出对话框的方法。

我已经阅读了 CodeGuru 和 Feng Yuan(MSDN)的相关文章,以及许多讨论主题,但我仍然感到困惑。

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

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


你能稍微澄清一下问题吗?你正在使用哪种编程语言?你是特别想从应用程序中创建XPS输出,还是仅仅因为XPS文档编写器是默认驱动程序而弹出对话框干扰了应该自动化的工作流程? - Jon
也许你阅读过一些链接,如果你提供它们可能会有帮助解决你的问题。 - Nocturnal
Jon - 这个问题是关于创建打印机驱动程序的。这是一个自动化的过程,可以打印到计算机的默认打印机。- Nocturnal,谢谢你,但事实上我放弃了这个解决方案并购买了第三方产品。 - Chen Harel
2个回答

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)

0

您需要在管道 XML 中删除过滤器,还要在 INF 文件中删除相关的 DLL。但是和我一样,您可能会遇到打印画布(图形)的问题。我无法将这个画布转换/转换为字形,以获取其内容。

如果您有进一步的问题,请告诉我。

此致敬礼


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接