Articles in this section
Category / Section

Printing the PowerPoint presentation with Essential Presentation library

2 mins read

You can print the presentation document by converting the PowerPoint Presentation slides to images. The System.Drawing.Printing. PrintDocument class can be used to print the converted images by the default printer or to any of the available printer with customized settings.


The following code example demonstrates how to convert the slides of a PowerPoint presentation to images.


//Opens a PowerPoint presentation
IPresentation presentation = Presentation.Open("Sample.pptx");
//Converts the slides to images
Image[] images = presentation.RenderAsImages(Syncfusion.Drawing.ImageType.Bitmap);
//Closes the PowerPoint presentation


The following code example demonstrates how to print the converted images.


//Initializes the start and end page for printing
int startPageIndex = 1;
int endPageIndex = images.Length;
//Creates new PrintDialog instance.
System.Windows.Forms.PrintDialog printDialog = new System.Windows.Forms.PrintDialog();
//Sets new PrintDocument instance to print dialog.
printDialog.Document = new PrintDocument();
//Enables the print current page option.
printDialog.AllowCurrentPage = true;
//Enables the print selected pages option.
printDialog.AllowSomePages = true;
//Sets the start and end page index
printDialog.PrinterSettings.FromPage = 1;
printDialog.PrinterSettings.ToPage = images.Length;
//Opens the print dialog box.
if (printDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
//Checks whether the selected page range is valid or not
if (printDialog.PrinterSettings.FromPage > 0 && printDialog.PrinterSettings.ToPage <= images.Length)
//Updates the start page of the document to print.
startPageIndex = printDialog.PrinterSettings.FromPage - 1;
//Updates the end page of the document to print.
endPageIndex = printDialog.PrinterSettings.ToPage;
//Hooks the PrintPage event to handle be drawing pages for printing.
printDialog.Document.PrintPage += new PrintPageEventHandler(PrintPageMethod);
//Prints the document.
private void PrintPageMethod(object sender, PrintPageEventArgs e)
//Gets the print start page width.
int currentPageWidth = images[startPageIndex].Width;
//Gets the print start page height.
int currentPageHeight = images[startPageIndex].Height;
//Gets the visible bounds width for print.
int visibleClipBoundsWidth = (int)e.Graphics.VisibleClipBounds.Width;
//Gets the visible bounds height for print.
int visibleClipBoundsHeight = (int)e.Graphics.VisibleClipBounds.Height;
//Checks whether the page layout is landscape or portrait.
if (currentPageWidth > currentPageHeight)
//Translates the position.
e.Graphics.TranslateTransform(0, visibleClipBoundsHeight);
//Rotates the object at 270 degrees
//Draws the current page image.
e.Graphics.DrawImage(images[startPageIndex], new System.Drawing.Rectangle(0, 0, currentPageWidth, currentPageHeight));
//Draws the current page image.
e.Graphics.DrawImage(images[startPageIndex], new System.Drawing.Rectangle(0, 0, visibleClipBoundsWidth, visibleClipBoundsHeight));
//Disposes the current page image after drawing.
//Increments the start page index.
//Updates whether the document contains more pages to print or not.
if (startPageIndex < endPageIndex)
e.HasMorePages = true;
startPageIndex = 0;


You can find the complete sample here.

Did you find this information helpful?
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment