我在尋找可以打印Microsoft Office和PDF文件的Java API。我也想提供打印規格,即使在系統上沒有打開這些文件的軟件。商業圖書館很好。你可以推薦任何?用Java打印Microsoft Office和PDF文件
回答
對於PDF打印這裏是免費的!使用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);
}
}
但我仍然需要一個MS Office文件的解決方案! – Harinder 2011-06-03 05:12:57
首先將Office文檔轉換爲PDF,然後打印。對於docx,請嘗試docx4j;對於xlsx和舊的二進制格式,請嘗試POI,或者對於非Java方法,請嘗試OpenOffice。 – JasonPlutext 2011-06-03 12:16:50
您可以在Java中使用的支柱顯示錶標籤,您的數據導出爲XLS,PDF,CVS格式,然後可以打印。
語法非常簡單,只需將您的集合提供給顯示錶,它將在jsp上顯示集合本身的內容,如果您設置「export = true」,則可以輕鬆地將文件導出爲pdf或xls格式。
訪問這裏:
http://displaytag.sourceforge.net/11/displaytag/tlddoc/display/table.html
看一看OpenOffice的API,還有一些printing examples provided。 OpenOffice可以打開MS Office文檔,但給定的API非常有限。
Aspose擁有一套用於Word,Excel,PDF的產品。您可以導出到不同的格式,包括PDF和打印。
嘗試的Apache POI微軟文檔http://poi.apache.org/
對於打印設置請參考這個網址http://poi.apache.org/apidocs/org/apache/poi/hssf/usermodel/HSSFPrintSetup.html
- 1. WPF可以直接打印PDF和Office文件嗎?
- 2. 用java打印PDF
- 3. 打印PDF文件
- 4. Java在Mac中打印PDF文件
- 5. ASP.NET打印控件和PDF中的Microsoft和Dundes圖表
- 6. 如何打印PDF文件在Java中與打印對話框
- 7. Ascii打印文件爲PDF
- 8. CUPS打印PDF文件
- 9. 從Qt打印PDF文件
- 10. 打印PDF文件與PDFSharp
- 11. 使用pdf打印機打印文檔
- 12. 打印PDF和刪除文件時,打印完成
- 13. BY_HANDLE_FILE_INFORMATION結構 - Microsoft Office文件
- 14. 使用C#打印PDF文件和Doc文件
- 15. 用於打印PDF文件的SDK
- 16. 使用PHP打印PDF文件
- 17. 如何使用Prolog打印PDF文件
- 18. 什麼是解析Microsoft Office和PDF文檔的最佳方式?
- 19. 用Java打印
- 20. 的Java Applet PDF打印
- 21. Apex Office打印插件:下載PDF報告時出錯
- 22. 在Java中使用PrinterJob打印PDF文件
- 23. 使用java或javascript將網頁打印成pdf文件
- 24. 用Java打開Microsoft Word docx文件
- 25. Microsoft office 2007和endnote
- 26. 將office文件轉換爲pdf與documents4J
- 27. Java:使用Apache POI打印?
- 28. 單獨的樣式表用於打印和PDF文件?
- 29. 使用Python,win32api和Acrobat Reader打印PDF文件9
- 30. 打印PDF雙面打印
您可以使用我們的產品的Gnostice PDFOne(用於Java),這裏是我們的PDF印刷演示 - [如何打印PDF Document in Java](http://www.gnostice.com/nl_article.asp?id=160&t=How_to_Print_a_PDF_Document_in_Java)。 PDFOne附帶免版稅的商業許可證。 – BZ1 2011-06-02 05:41:26
我不想要任何對話來在前面!我只想通過我的應用程序中的所有規範 – Harinder 2011-06-02 05:46:00
如果您不想使用該對話框,則無需調用PDFPrinter.showPrintDialog()方法。相反,調用PdfPrinter.print(String pageRange,int numOfCopies)方法。它在最後一行中的文章中提到。 – BZ1 2011-06-02 06:01:01