Category Archives: printing

Print a text file in C#

This example lets you select a printer and file, and then print the file on the selected printer. (Actually this version just displays a print preview. To send the file directly to the selected printer, see the example Send a … Continue reading

Posted in printers, printing, system | Tagged , , , , , , , , , , , , , , , , , | 2 Comments

Restart the print spooler in C#

Every now and then my computer gets confused and thinks the printer is offline. That wouldn’t be so bad except Windows doesn’t provide a simple way to bring the printer back online. Basically you need to shutdown and restart the … Continue reading

Posted in printing, system | Tagged , , , , , , , , , , | 7 Comments

Print images in C#

This example shows a simple way to print images. When you print, the PrintDocument object’s PrintPage event handler provides a Graphics object named e.Graphics. That object’s DrawImage method can draw a picture on the printed surface. To print an image, … Continue reading

Posted in graphics, image processing, printing | Tagged , , , , , , , , , , | Leave a comment

Print at full scale in C#

This example shows how you can print at full scale so objects drawn on the screen are the same size when printed. Note that your screen and printer are probably not calibrated exactly so the result will not match perfectly. … Continue reading

Posted in drawing, GDI+, graphics, printing | Tagged , , , , , , , , , , , , , , , , | 2 Comments

Select printer resolution in C#

This example shows how to let the user select a printer resolution. When you set a PrintDocument object’s printer, its DefaultPageSettings.PrinterSettings.PrinterResolutions collection contains PrinterResolution objects representing the printer’s available resolutions. For example, you can select one of these to print … Continue reading

Posted in printers, printing | Tagged , , , , , , , , | Leave a comment

Let the user select a printer and then send a printout directly to it in C#

When it starts, the program uses the following code to list the available printers in a ComboBox. // List the available printers. private void Form1_Load(object sender, EventArgs e) { foreach (string printer in PrinterSettings.InstalledPrinters) cboPrinter.Items.Add(printer); } This code loops through … Continue reading

Posted in printers, printing | Tagged , , , , , , , , , , | Leave a comment

Send a printout directly to a specific printer in C#

To send a printout directly to a specific printer, simply set the PrintDocument object’s PrinterSettings.PrinterName property to the printer’s name. This example uses the following code to print directly to the printer named “HP Deskjet F300 Series.” // Print. private … Continue reading

Posted in printers, printing | Tagged , , , , , , , , | 3 Comments

Display Pascal’s triangle in C#

In Pascal’s triangle, each row has a 1 on either end. An entry between the ends is the sum of the two entries above it. Mathematically you can define the Nth entry on row R as: Entry(R, N) = Entry(R … Continue reading

Posted in algorithms, mathematics, printing | Tagged , , , , , , , , | Leave a comment

Change print orientation and margins in C#

This example shows how to change the print orientation and margins in a printout or print preview. By default, when you display a print preview or print a document, the document appears in portrait orientation with one inch margins. To … Continue reading

Posted in printing | Tagged , , , , , , , , , | 1 Comment

Print a grid of values with alternating row colors in C#

The following code shows how the program prints its grid. The complete code isn’t too complicated but it’s long so here it’s broken into several methods. // Draw the grid. private void pdocGrid_PrintPage(object sender, PrintPageEventArgs e) { // Make some … Continue reading

Posted in graphics, printing | Tagged , , , , , , , , , , | 1 Comment