Set a print job's document name in C#

By default, when you send a PrintDocument to a printer, the printer spool shows the job's name as "document." You can change that name by setting the PrintDocument's DocumentName property.
This example uses the following code to print a small sample document.

// Print the document.
private void btnPrint_Click(object sender, EventArgs e)
{
    // Select the printer.
    pdocFile.PrinterSettings.PrinterName = cboPrinter.Text;

    // Set the print document name.
    pdocFile.DocumentName = txtDocumentName.Text;

    // Print.
    pdocFile.Print();
}

The code sets the PrintDocument's PrinterSettings.PrinterName property so output goes to the printer you selected from the ComboBox at the top of the form.

It then sets the DocumentName property to the value you entered in the TextBox.

Finally the code calls the PrintDocument object's Print method to start printing.

If you click the Print button and then check the selected printer's spool (before the document has finished printing), you should see the document name you entered.

   

 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this post.
Comments
  • No comments exist for this post.
Leave a comment

Submitted comments are subject to moderation before being displayed.

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.