静默使用 Microsoft XPS Document Writer 打印机创建 XPS

发布于 2024-10-20 10:10:14 字数 306 浏览 5 评论 0原文

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

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

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

For some days now I've been battling with printing XPS to file without the dialog.
I've read posts on the matter in CodeGuru and by Feng Yuan (MSDN), along with many discussion topics here and I am still lost.

Specifically my scenario is that I have a 3rd party API that I must use, and it prints to the default printer (say Microsoft XPS Document Writer). I want to be able to "apply" a filename prior to the printing procedure, and of course not to have dialog.

I've tried working with WinDDK - XPSDRV and LOCALMON samples but wasn't able to figure out exactly how to manipulate the code to achieve my goals. (or even fully understand if I need a new printer driver or a new port type)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

习惯成性 2024-10-27 10:10:14

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

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

I ran into the same need. Following is some of the logic that provides the desired functionality for me:

 // 
 // 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)
随风而去 2024-10-27 10:10:14

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

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

亲切的问候

You will delete filters in pipeline xml and also related dll's in inf file. But yet, as I did, i guess you will face problem of printing canvas (graphics). I wasn't able to convert / transform this canvas to glyphs to get the contents of it.

If you had further issues, let me know

Kind Regards

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文