Print (3)
PowerPoint print settings allow users to control how presentation slides are printed, such as print all slides, print some selected slides, print slides with frames or not, print many slides into one page, print order, print color and so on. This article will show you how to set print options when print PowerPoint documents in C#.
Firstly, view Microsoft PowerPoint's page print settings:
Code Snippets of set print settings of PowerPoint document by using PrinterSettings object to print the presentation slides:
static void Main(string[] args) { //load the sample document from file Presentation ppt = new Presentation(); ppt.LoadFromFile("Sample.pptx"); //use PrinterSettings object to print presentation slides PrinterSettings ps = new PrinterSettings(); ps.PrintRange = PrintRange.AllPages; ps.PrintToFile = true; ps.PrintFileName = ("Print.xps"); //print the slide with frame ppt.SlideFrameForPrint = true; //print the slide with Grayscale ppt.GrayLevelForPrint = true; //Print 4 slides horizontal ppt.SlideCountPerPageForPrint = PageSlideCount.Four; ppt.OrderForPrint = Order.Horizontal; ////only select some slides to print //ppt.SelectSlidesForPrint("1", "3"); //print the document ppt.Print(ps); }
Code Snippets of set print document name by using PrintDocument object to print presentation slides:
static void Main(string[] args) { //load the sample document from file Presentation ppt = new Presentation(); ppt.LoadFromFile("Sample.pptx"); //use PrintDocument object to print presentation slides PresentationPrintDocument document = new PresentationPrintDocument(ppt); //print document to virtual printer document.PrinterSettings.PrinterName = "Microsoft XPS Document Writer"; //print the slide with frame ppt.SlideFrameForPrint = true; //print 4 slides horizontal ppt.SlideCountPerPageForPrint = PageSlideCount.Four; ppt.OrderForPrint = Order.Horizontal; //print the slide with Grayscale ppt.GrayLevelForPrint = true; //set the print document name document.DocumentName = "Print Task"; document.PrinterSettings.PrintToFile = true; document.PrinterSettings.PrintFileName = ("Print.xps"); ppt.Print(document); }
Use PrintDocument object to print a PowerPoint document
2017-10-10 07:07:25 Written by support iceblueSpire.Presentation has a powerful function to print PowerPoint document. From Spire.Presentation v 2.8.59, it supports to use the PrintDocument object to print the presentation slides. This example shows how to print presentation slides using C# via the following print methods:
- Print PowerPoint document to default printer.
- Print PowerPoint document to virtual printer.
- Print some pages from the PowerPoint document and set the document name, number of copies while printing the presentation slides.
Print presentation slides to default printer and print all the pages on the PowerPoint document.
using Spire.Presentation; using System.Drawing.Printing; namespace PrintPPT { class Program { static void Main(string[] args) { Presentation ppt = new Presentation(); ppt.LoadFromFile("Sample.pptx"); PresentationPrintDocument document = new PresentationPrintDocument(ppt); document.PrintController = new StandardPrintController(); ppt.Print(document); } } }
Print PowerPoint document to virtual printer (Microsoft XPS Document Writer).
using Spire.Presentation; namespace PrintPPT { class Program { static void Main(string[] args) { Presentation ppt = new Presentation(); ppt.LoadFromFile("Sample.pptx"); PresentationPrintDocument document = new PresentationPrintDocument(ppt); document.PrinterSettings.PrinterName = "Microsoft XPS Document Writer"; ppt.Print(document); } } }
Print some pages from the PowerPoint document and set the document name, number of copies while printing the presentation slides.
using Spire.Presentation; using System.Drawing.Printing; namespace PrintPPT { class Program { static void Main(string[] args) { Presentation ppt = new Presentation(); ppt.LoadFromFile("Sample.pptx"); PresentationPrintDocument document = new PresentationPrintDocument(ppt); //Set the document name to display while printing the document document.DocumentName = "Print PowerPoint"; //Choose to print some pages from the PowerPoint document document.PrinterSettings.PrintRange = PrintRange.SomePages; document.PrinterSettings.FromPage = 1; document.PrinterSettings.ToPage = 2; //Set the number of copies of the document to print document.PrinterSettings.Copies = 2; ppt.Print(document); } } }
Spire.Presentation for .NET, a reliable .NET PPT component, enables you to generate, read, edit, convert even print your PPT documents without installing Microsoft PowerPoint on your machine. Using Spire.Presentation for .NET, you can use the presentation.Print() method to print your PPT documents in a fast speed.The following article will introduce a detail method to print a PPT document with C#, VB via Spire.Presentation for .NET.
Download and install Spire.Presentation for .NET and use below code to experience this method to print PPT document.
The main steps of method are:
Step 1: Create a PPT document.
Presentation presentation = new Presentation();
Step 2: Append new shape and paragraph to add the text.
IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 150, 600, 250)); shape.TextFrame.Paragraphs.Append(new TextParagraph());
Step 3: Set the background to DarkSeaGreen.
presentation.Slides[0].SlideBackground.Type = BackgroundType.Custom; presentation.Slides[0].SlideBackground.Fill.FillType = FillFormatType.Solid; presentation.Slides[0].SlideBackground.Fill.SolidColor.Color = Color.DarkSeaGreen;
Step 4: Create a printerSettings and print the PPT.
PrinterSettings printerSettings = new PrinterSettings(); presentation.Print(printerSettings);
Suppose you've succeeded use the method, the printer icon would appear in the lower right corner ofscreen. such as:
If you couldn't successfully use the Spire.presentation, please refer the Spire.Presentation Quick Start which can guide you quickly use the Spire.presentation.
The full code:
using System.Drawing; using System.Drawing.Printing; using Spire.Presentation; using Spire.Presentation.Drawing; namespace PrintPPT { class Program { static void Main(string[] args) { //create PPT document Presentation presentation = new Presentation(); //append new shape IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 150, 600, 250)); shape.ShapeStyle.LineColor.Color = Color.DarkSeaGreen; shape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.None; //add text to shape shape.AppendTextFrame("The sample demonstrates how to Print PPT file."); //add new paragraph shape.TextFrame.Paragraphs.Append(new TextParagraph()); //add text to paragraph shape.TextFrame.Paragraphs[1].TextRanges.Append(new TextRange("As an independent Office .NET component, Spire.Office doesn't need Microsoft Office to be installed on System. In addition, it is a better alternative to MS Office Automation in terms of security, stability, scalability, speed, price and features.")); //set the Font foreach (TextParagraph para in shape.TextFrame.Paragraphs) { para.TextRanges[0].LatinFont = new TextFont("Arial Rounded MT Bold"); para.TextRanges[0].Fill.FillType = FillFormatType.Solid; para.TextRanges[0].Fill.SolidColor.Color = Color.Black; para.Alignment = TextAlignmentType.Left; para.Indent = 35; } //set the background to DarkSeaGreen presentation.Slides[0].SlideBackground.Type = BackgroundType.Custom; presentation.Slides[0].SlideBackground.Fill.FillType = FillFormatType.Solid; presentation.Slides[0].SlideBackground.Fill.SolidColor.Color = Color.DarkSeaGreen; //print PrinterSettings printerSettings = new PrinterSettings(); presentation.Print(printerSettings); } } }
Imports System.Drawing Imports System.Drawing.Printing Imports Spire.Presentation Imports Spire.Presentation.Drawing Namespace PrintPPT Class Program Private Shared Sub Main(args As String()) 'create PPT document Dim presentation As New Presentation() 'append new shape Dim shape As IAutoShape = presentation.Slides(0).Shapes.AppendShape(ShapeType.Rectangle, New RectangleF(50, 150, 600, 250)) shape.ShapeStyle.LineColor.Color = Color.DarkSeaGreen shape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.None 'add text to shape shape.AppendTextFrame("The sample demonstrates how to Print PPT file.") 'add new paragraph shape.TextFrame.Paragraphs.Append(New TextParagraph()) 'add text to paragraph shape.TextFrame.Paragraphs(1).TextRanges.Append(New TextRange("As an independent Office .NET component, Spire.Office doesn't need Microsoft Office to be installed on System. In addition, it is a better alternative to MS Office Automation in terms of security, stability, scalability, speed, price and features.")) 'set the Font For Each para As TextParagraph In shape.TextFrame.Paragraphs para.TextRanges(0).LatinFont = New TextFont("Arial Rounded MT Bold") para.TextRanges(0).Fill.FillType = FillFormatType.Solid para.TextRanges(0).Fill.SolidColor.Color = Color.Black para.Alignment = TextAlignmentType.Left para.Indent = 35 Next 'set the background to DarkSeaGreen presentation.Slides(0).SlideBackground.Type = BackgroundType.[Custom] presentation.Slides(0).SlideBackground.Fill.FillType = FillFormatType.Solid presentation.Slides(0).SlideBackground.Fill.SolidColor.Color = Color.DarkSeaGreen 'print Dim printerSettings As New PrinterSettings() presentation.Print(printerSettings) End Sub End Class End Namespace