2011-03-03 56 views
2

幾天以來,我一直在與沒有對話框的XPS打印文件作鬥爭。 我已閱讀CodeGuru和Feng Yuan(MSDN)關於此事的帖子,以及許多討論主題,但我仍然迷失。靜默使用Microsoft XPS Document Writer打印機創建XPS

具體來說,我的方案是我有一個第三方API,我必須使用它,並打印到默認打印機(比如說Microsoft XPS Document Writer)。我希望能夠在打印過程之前「應用」一個文件名,當然不會有對話框。

我已經嘗試使用WinDDK-XPSDRV和LOCALMON示例,但無法弄清楚如何操作代碼來實現我的目標。 (甚至完全理解是否需要新的打印機驅動程序或新的端口類型)

+0

你能澄清一下這個問題嗎?你在用什麼語言工作?您是否專門嘗試從您的應用程序創建XPS輸出,還是僅僅當XPS Document Writer是默認驅動程序時,彈出對話框會干擾應該是自動化工作流的內容? – Jon 2011-03-03 20:05:21

+0

也許您已閱讀的某些鏈接,如果您提供這些鏈接以幫助您解決問題,可能會有所幫助。 – Nocturnal 2011-03-04 08:25:19

+0

喬恩 - 問題是關於創建一個打印機驅動程序。這是一個打印到計算機默認打印機的自動化過程。 - 夜間,謝謝,但實際上我離開了這個解決方案,併購買了第三方產品。 – 2011-04-06 08:09:11

回答

0

您將刪除管道xml中的過濾器以及相關的dll在inf文件中。但是,和我一樣,我猜你會遇到打印畫布(圖形)的問題。我無法將此畫布轉換/轉換爲字形以獲取其內容。

如果你有進一步的問題,讓我知道

親切的問候

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) 
相關問題