Print Microsoft Office and PDF files in Java

I am looking for Java APIs that can print Microsoft Office and PDF files. I would also like to provide print specifications, even if there is no software to open these files on the system. Commercial libraries are fine. Can you recommend someone?

+4
source share
5 answers

Print PDF here is the best solution for free! Use PDFBox ..

import java.awt.print.PrinterJob; import javax.print.PrintService; import javax.print.PrintServiceLookup; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.util.PDFTextStripper; public class PrintPDF { private static final String PASSWORD = "-password"; private static final String SILENT = "-silentPrint"; private static final String PRINTER_NAME = "-printerName"; /** * private constructor. */ private PrintPDF() { //static class } public static void main( String pdfFilepath,String printerindx ) throws Exception { String password = ""; String pdfFile = pdfFilepath; boolean silentPrint = true; PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService(); if( pdfFile == null ) { usage(); } PDDocument document = null; try { document = PDDocument.load( pdfFile ); if( document.isEncrypted() ) { document.decrypt( password ); } PrinterJob printJob = PrinterJob.getPrinterJob(); if(printerindx != null ) { PrintService[] printService = PrinterJob.lookupPrintServices(); printJob.setPrintService(printService[Integer.parseInt(printerindx)]); } txt=new PDDocument(document); if( silentPrint ) { document.silentPrint( printJob ); } else { document.print( printJob ); } } finally { if( document != null ) { document.close(); } } } /** * This will print the usage requirements and exit. */ private static void usage() { System.err.println( "Usage: java org.apache.pdfbox.PrintPDF [OPTIONS] <PDF file>\n" + " -password <password> Password to decrypt document\n" + " -silentPrint Print without prompting for printer info\n" ); System.exit( 1 ); } } 
+4
source

Check out the OpenOffice API, there are some printing examples . OpenOffice can open MS Office documents, but this API is very limited.

+1
source

Aspose has a set of products for working with Word, Excel, PDF. You can export to various formats, including PDF, and print.

+1
source

You can use display-table struts tags in java to export your data in xls, pdf, cvs format, and then you can print.

The syntax is very simple, just provide your collection with a mapping table and it will display the contents of the collection itself on jsp, and if you set "export = true", you can easily export your file in pdf or xls format.

Visit here:

http://displaytag.sourceforge.net/11/displaytag/tlddoc/display/table.html

0
source

try Apache POI for Microsoft docs http://poi.apache.org/

To configure printing, refer to this URL http://poi.apache.org/apidocs/org/apache/poi/hssf/usermodel/HSSFPrintSetup.html

0
source

All Articles