Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

E-iceblue Product Family
E-iceblue Product Family

Posted on

Print PowerPoint Documents in Java Applications

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 fromthis link and add it as a dependency in your application.

<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>
Enter fullscreen modeExit fullscreen mode

Example 1. Print with network connected printer

importcom.spire.ms.Printing.PrinterSettings;importcom.spire.presentation.Presentation;importcom.spire.presentation.PresentationPrintDocument;publicclassPrintPowerPointFile{publicstaticvoidmain(String[]args)throwsException{//Create a Presentation objectPresentationpresentation=newPresentation();//Load the PowerPoint documentpresentation.loadFromFile("C:\\Users\\Administrator\\Desktop\\sample.pptx");//Create a PresentationPrintDocument objectPresentationPrintDocumentprintDocument=newPresentationPrintDocument(presentation);//Print the slide with GrayscaleprintDocument.setGrayLevelForPrint(true);//Get the printer settingsPrinterSettingsprinterSettings=printDocument.getPrinterSettings();//Set print rangeprinterSettings.setFromPage(1);printerSettings.setToPage(4);//Set printer nameprinterSettings.setPrinterName("HP ColorLaserJet MFP M278-M281 PCL-6 (V4)");//Set print copyprinterSettings.setCopies((short)1);//Call print method to print the selected pagesprintDocument.print();presentation.dispose();}}
Enter fullscreen modeExit fullscreen mode

Example 2. Print with virtual printer

importcom.spire.ms.Printing.PrinterSettings;importcom.spire.presentation.Presentation;importcom.spire.presentation.PresentationPrintDocument;publicclassPrintToDocument{publicstaticvoidmain(String[]args)throwsException{//Create a Presentation objectPresentationpresentation=newPresentation();//Load the PowerPoint documentpresentation.loadFromFile("C:\\Users\\Administrator\\Desktop\\sample.pptx");//Create a PresentationPrintDocument objectPresentationPrintDocumentprintDocument=newPresentationPrintDocument(presentation);//Get the printer settingsPrinterSettingsprinterSettings=printDocument.getPrinterSettings();//Set printer nameprinterSettings.setPrinterName("Microsoft Print to PDF");printerSettings.setPrintToFile(true);printerSettings.setPrintFileName("out/PrintToPdf.pdf");printDocument.print();presentation.dispose();}}
Enter fullscreen modeExit fullscreen mode

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Your Office Development Master
  • Location
    Chengdu, SiChuan, China
  • Work
    Dev at E-iceblue
  • Joined

More fromE-iceblue Product Family

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp