天天看點

列印系統開發(58)——列印系統開發筆記一、列印控件:二、相關軟體三、相關屬性四、相關連結五、右鍵菜單六、列印PDF需要用到的元件和驅動七、驅動程式設定八、驅動

一、列印控件:

  PrintDocument:要列印的對象。

  PageSetupDialog:列印設定對話框。

  PrintPreviewControl:列印預覽控件。

  PrintPreviewDialog:列印預覽對話框。

  PrintDialog:列印對話框。

二、相關軟體

我們的産品是基于Adobe來開發的,我們首先得知道這個功能具體是如何實作的,才好調查用我們的産品如何去實作。是以首先得知道用的是Adobe的哪個版本。

三、相關屬性

1、PrintDocument.DocumentName 屬性

命名空間:

System.Drawing.Printing

程式集:

System.Drawing.dll, System.Drawing.Common.dll

列印文檔時擷取或設定要顯示的文檔名稱(例如,在列印狀态對話框中或在列印機隊列中)。從中繼資料:

public string DocumentName { get; set; }
           

示例

下面的代碼示例使用顔色列印第一頁,如果列印機支援該文檔,并将設定DocumentName為使用者友好名稱。 該示例需要建立一個PrintDocument名為

printDoc

的變量, PrintPage并處理和QueryPageSettings事件。

在System.Drawing此示例System.Drawing.Printing中使用和命名空間。

private void MyButtonPrint_OnClick(object sender, System.EventArgs e)
{
    
    // Set the printer name and ensure it is valid. If not, provide a message to the user.
    printDoc.PrinterSettings.PrinterName = "\\mynetworkprinter";

    if (printDoc.PrinterSettings.IsValid) {
    
        // If the printer supports printing in color, then override the printer's default behavior.
        if (printDoc.PrinterSettings.SupportsColor) {

            // Set the page default's to not print in color.
            printDoc.DefaultPageSettings.Color = false;
        }

        // Provide a friendly name, set the page number, and print the document.
        printDoc.DocumentName = "My Presentation";
        currentPageNumber = 1;
        printDoc.Print();
    }
    else {
        MessageBox.Show("Printer is not valid");
    }
}

private void MyPrintQueryPageSettingsEvent(object sender, QueryPageSettingsEventArgs e)
{
    // Determines if the printer supports printing in color.
    if (printDoc.PrinterSettings.SupportsColor) {

        // If the printer supports color printing, use color.
        if (currentPageNumber == 1 ) {

            e.PageSettings.Color = true;
        }

    }    
}
           

轉自:https://docs.microsoft.com/zh-cn/dotnet/api/system.drawing.printing.printdocument.documentname?redirectedfrom=MSDN&view=netframework-4.8#System_Drawing_Printing_PrintDocument_DocumentName

2、PrintDocument.PrintController 屬性 (System.Drawing.Printing),列印控制器

擷取或設定指導列印程序的列印控制器。

命名空間:   System.Drawing.Printing

程式集:  System.Drawing(位于 System.Drawing.dll)

從中繼資料:

[System.ComponentModel.Browsable(false)]
public System.Drawing.Printing.PrintController PrintController { get; set; }
           
public PrintController PrintController { get; set; }
           

示例:

public void myPrint()
{
   if (useMyPrintController == true)
   {
      myPrintDocument.PrintController = 
         new myControllerImplementation();     
      if (wantsStatusDialog == true)
      {
         myPrintDocument.PrintController = 
            new PrintControllerWithStatusDialog
            (myPrintDocument.PrintController);
      }
   }
   myPrintDocument.Print();
}
           

屬性值

Type:

PrintController 指導列印程序。 預設值為的新執行個體 PrintControllerWithStatusDialog 類。

備注

一個列印控制器指導列印程序中有多種。 例如,若要列印文檔時,需要将其轉換為 Graphics 對象。 一個 PrintController 指定在為列印預覽或列印文檔的實際的列印機上的圖像中繪制圖形的位置。 一個列印控制器還可以指定是否立即列印文檔或等待指定的時間間隔。

示例

下面的代碼示例要求您已建立的一個執行個體 PrintDocument 類名為myPrintDocument。 該示例建立的新執行個體 PrintController 類中,将它配置設定給 屬性myPrintDocument, ,并列印該文檔。

使用 System.Drawing.Printing 和 System.Windows.Forms 對于此示例的命名空間。

public void myPrint() 
{ 
   if (useMyPrintController == true) 
   { 
      myPrintDocument.PrintController =  
         new myControllerImplementation();      
      if (wantsStatusDialog == true) 
      { 
         myPrintDocument.PrintController =  
            new PrintControllerWithStatusDialog 
            (myPrintDocument.PrintController); 
      } 
   } 
   myPrintDocument.Print(); 
} 
Public Sub myPrint()
    If useMyPrintController = True Then
        myPrintDocument.PrintController = New myControllerImplementation()
        If wantsStatusDialog = True Then
            myPrintDocument.PrintController = _
               New PrintControllerWithStatusDialog( _
               myPrintDocument.PrintController)
        End If
    End If
    myPrintDocument.Print()
End Sub
public: 
   void myPrint() 
   { 
      if ( useMyPrintController == true ) 
      { 
         myPrintDocument->PrintController = 
            gcnew myControllerImplementation; 
         if ( wantsStatusDialog == true ) 
         { 
            myPrintDocument->PrintController = 
               gcnew PrintControllerWithStatusDialog( 
                  myPrintDocument->PrintController ); 
         } 
      } 
      myPrintDocument->Print(); 
   }
           

整理自:https://docs.microsoft.com/es-es/dotnet/api/system.drawing.printing.printdocument.printcontroller?redirectedfrom=MSDN&view=netframework-4.8#System_Drawing_Printing_PrintDocument_PrintController

https://msdn.microsoft.com/zh-cn/vstudio/system.drawing.printing.printdocument.printcontroller(v%3Dvs.95)

3、public bool IsValid { get; }

        // 摘要:

        //     擷取一個值,該值訓示是否 System.Drawing.Printing.PrinterSettings.PrinterName 屬性指定有效的列印機。

        //

        // 傳回結果:

        //     true 如果 System.Drawing.Printing.PrinterSettings.PrinterName 屬性指定有效的列印機; 否則為 false。

        public bool IsValid { get; }

IsValid 是Page的屬性,用于判斷頁面上的驗證控件是否均通過驗證,如果頁面上沒有驗證控件,則不必做這個判斷了。

四、相關連結

1、System.Drawing.Printing 命名空間

https://docs.microsoft.com/zh-cn/dotnet/api/system.drawing.printing?view=netframework-4.8

2、PrinterSettings 類

https://docs.microsoft.com/zh-cn/dotnet/api/system.drawing.printing.printersettings?redirectedfrom=MSDN&view=netframework-4.8

五、右鍵菜單

contextMenuStrip1

從工具箱中找到這個控件,拖到窗體上,這是一個非可視化控件。

1、删除指定行[D]

2、提取PDF頁面[E]

3、解除PDF限制[R]

4、清除PDF密碼[L]

5、轉換到PDF[T]

6、合并到PDF[M]

7、列出所有檔案[S]

8、清空清單[P]

9、擷取檔案個數[N]

10、統計費用[A]

六、列印PDF需要用到的元件和驅動

1、Adobe Acrobat Reader DC

2、Foxit Reader(福昕PDF閱讀器)

七、驅動程式設定

列印系統開發(58)——列印系統開發筆記一、列印控件:二、相關軟體三、相關屬性四、相關連結五、右鍵菜單六、列印PDF需要用到的元件和驅動七、驅動程式設定八、驅動
列印系統開發(58)——列印系統開發筆記一、列印控件:二、相關軟體三、相關屬性四、相關連結五、右鍵菜單六、列印PDF需要用到的元件和驅動七、驅動程式設定八、驅動

八、驅動

程式(驅動)将轉化好的列印檔案,按照各種列印機的不同格式發送給列印機,是應用層程式與底層列印機硬體互動的媒介。不同列印機映射到的驅動程式是不同的。