最近在研究winform打印文件,需要支持word,excel,ppt,pdf,圖片這幾種格式,不能依賴相關軟件環境,研究后決定使用Aspose套件將相關文件全部轉換成pdf后打印
WrodToPDF
使用Aspose.Word 11.9,需要配合licence文件破解
ExcelToPDF
使用Aspose.Cell 8.3(破解版本)
PPTToPDF
使用Aspose.Slides 16.9(需要配合代碼破解)
圖片ToPDF
使用Aspose.Pdf 9.4(需要配合代碼破解)
PDF文件打印
使用Aspose.Pdf打印文件可以直接設置打印機名稱,分數,方向d等
System.Drawing.Printing.PrinterSettings ps = new System.Drawing.Printing.PrinterSettings(); ps.PrinterName = PrinterName; ps.Copies = Copies; ps.Duplex = Direction; PdfViewer viewer = new PdfViewer(); viewer.BindPdf(PrintFileName); viewer.PrintDocumentWithSettings(ps); viewer.Close();
注:對於excel轉換pdf后是沒有表格線的,ppt轉換pdf后打印會被截斷,需要自己調整方向與紙張大小設置