Print excel file to pdf in landscape mode using C# -
i have project should print check bill in both excel , pdf format. use npoi print excel , spire print pdf using excel file:
public hssfworkbook workbook; public void saveexcelfile(string filepath) { this.autosizecolumn(); filepath = filepath == "" ? appdomain.currentdomain.basedirectory + "sample.xls" : filepath; var file = new filestream(filepath, filemode.create); workbook.write(file); file.close(); } public void savepdffilefromexcel(string excelfilepath, string pdffilepath) { workbook pdfworkbook = new workbook(); pdfworkbook.loadfromfile(excelfilepath); pdfworkbook.savetofile(pdffilepath, spire.xls.fileformat.pdf); }
but spire print pdf in portrait, , bill small , ugly. want know if there's way can print pdf in landscape.
or should use itext create pdf format self?
try this:
public void excellandscapeformat() { try { ((microsoft.office.interop.excel._worksheet) excelwbook.activesheet).pagesetup.orientation = microsoft.office.interop.excel.xlpageorientation.xllandscape; excelwbook.exportasfixedformat(xlfixedformattype.xltypepdf, path.getdirectoryname(assembly.getexecutingassembly().location) + "\\" + output); } catch { } }
Comments
Post a Comment