Print PowerPoint Documents in Java Applications
Tags: java, powerpoint, print
Published: 2021-04-13 08:39:19

---
title: Print PowerPoint Documents in Java Applications
published: true
description: This article shows you how to print PowerPoint documents in Java.
tags: java,powerpoint,print
//cover_image: https://direct_url_to_image.jpg
---
In this article, we’re going introduce how to send a PowerPoint document to a network connected printer or a virtual printer by using Spire.Prensetaion for Java. Spire provides the PresentationPrintDocument class to control how a PowerPoint presentation is printed, for example, print in grayscale, set the print range and copies. The following code snippets demonstrates the same.

##Installing Spire.Presentation.jar

If you create a Maven project, you can easily import the jar in your application using the following configurations. For non-Maven projects, download the jar file from [this link](https://www.e-iceblue.com/Download/presentation-for-java.html) and add it as a dependency in your application.
```java
<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>http://repo.e-iceblue.com/nexus/content/groups/public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId> e-iceblue </groupId>
        <artifactId>spire.presentation</artifactId>
        <version>4.1.6</version>
    </dependency>
</dependencies>
```
##Example 1. Print with network connected printer
```java
import com.spire.ms.Printing.PrinterSettings;
import com.spire.presentation.Presentation;
import com.spire.presentation.PresentationPrintDocument;

public class PrintPowerPointFile {

    public static void main(String[] args) throws Exception {

        //Create a Presentation object
        Presentation presentation = new Presentation();

        //Load the PowerPoint document
        presentation.loadFromFile("C:\\Users\\Administrator\\Desktop\\sample.pptx");

        //Create a PresentationPrintDocument object
        PresentationPrintDocument printDocument = new PresentationPrintDocument(presentation);

        //Print the slide with Grayscale
        printDocument.setGrayLevelForPrint(true);

        //Get the printer settings
        PrinterSettings printerSettings = printDocument.getPrinterSettings();

        //Set print range
        printerSettings.setFromPage(1);
        printerSettings.setToPage(4);

        //Set printer name
        printerSettings.setPrinterName("HP ColorLaserJet MFP M278-M281 PCL-6 (V4)");

        //Set print copy
        printerSettings.setCopies((short)1);

        //Call print method to print the selected pages
        printDocument.print();
        presentation.dispose();
    }
}
```
##Example 2. Print with virtual printer
```java
import com.spire.ms.Printing.PrinterSettings;
import com.spire.presentation.Presentation;
import com.spire.presentation.PresentationPrintDocument;

public class PrintToDocument {

    public static void main(String[] args) throws Exception {

        //Create a Presentation object
        Presentation presentation = new Presentation();

        //Load the PowerPoint document
        presentation.loadFromFile("C:\\Users\\Administrator\\Desktop\\sample.pptx");

        //Create a PresentationPrintDocument object
        PresentationPrintDocument printDocument = new PresentationPrintDocument(presentation);

        //Get the printer settings
        PrinterSettings printerSettings = printDocument.getPrinterSettings();

        //Set printer name
        printerSettings.setPrinterName("Microsoft Print to PDF");

        printerSettings.setPrintToFile(true);

        printerSettings.setPrintFileName("out/PrintToPdf.pdf");

        printDocument.print();
        presentation.dispose();
    }
}
```