# Print Document

Learn how to print document using PdfDocumentSource.

## Content



PdfDocumentSource allows you to print a PDF document programmatically. It provides support for printing using the [Print](/componentone/docs/win/online-documentlibrary/) method of the [C1DocumentSource](/componentone/docs/win/online-documentlibrary/) abstract class. The **Print** method has two overloads, **Print (PrinterSettings printerSettings)** and **Print (C1PrintOptions options)**. So, you can add the method using C1PdfDocumentSource to print a document without even the need of a viewer.

![Image showing user printing the files](https://cdn.mescius.io/document-site-files/images/a0c58113-bcd8-49ac-b5d4-2d50837f0be4/images/print-pdfdocsource.gif)

The following sections explain how the Print method can be used. The code snippets in this topic use the Print (C1PrintOptions options) method overload.

1.  Add a button control to the form for exporting PDF documents.
2.  Drag and drop **PdfDocumentSource** and **PrintDialog** components from the **Toolbox** on the form to add them to the component tray.
3.  Add the following namespace in the code view.
    
    ```csharp
    using C1.Win.C1Document;
    ```
    
4.  Add a PDF document to the project.
5.  Load the PDF document into the object of **C1PdfDocumentSource** class using [LoadFromFile](/componentone/docs/win/online-documentlibrary/#LOADFROMFILE) method:
    
    ```csharp
    c1PdfDocumentSource1.LoadFromFile(@"..\..\DefaultDocument.pdf");
    ```
    
6.  Add the following code to the button's click event to print the PDF document using **Print** method.<br />
    
    ```csharp
    private void btnPrint_Click(object sender, EventArgs e)
    {
               if (printDialog1.ShowDialog(this) != DialogResult.OK)
                    return;
                try
                {
                    C1PrintOptions po = new C1PrintOptions();
                    po.PrinterSettings = printDialog1.PrinterSettings;
                    //Print PDF
                    c1PdfDocumentSource1.Print(po);
                    MessageBox.Show(this, "Document was successfully printed.",
                                    "Information", MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
    }
    ```