日期:2014-05-17 浏览次数:20485 次
/// <summary>
/// excel转换为pdf
/// </summary>
/// <param name="file_inputname"></param>
public void PrintSheetToPDF(string fileInputName)
{
try
{
GetPrinterName(ref PrinterName, ref obj_printer_settings, ref oType);
PrintDocument prtdoc = new PrintDocument();
currentPrinterName = prtdoc.PrinterSettings.PrinterName; //获取默认的打印机名
//更改默认打印机
SetDefaultPrinter(PrinterName.Trim());
//通知更改
SendNotifyMessage(HWND_BROADCAST, WM_WININICHANGE, 0, "windows");
if (fileInputName == "")
{
return;
}
filePath = fileSavePath + "\\" + GetFileName(fileInputName) + ".pdf";
oType.InvokeMember("Init", System.Reflection.BindingFlags.InvokeMethod, null, obj_printer_settings, null);
oType.InvokeMember("SetValue", System.Reflection.BindingFlags.InvokeMethod, null, obj_printer_settings, new object[] { "output", filePath });
oType.InvokeMember("SetValue", System.Reflection.BindingFlags.InvokeMethod, null, obj_printer_settings, new object[] { "showsettings", "never" });
oType.InvokeMember("SetValue", System.Reflection.BindingFlags.InvokeMethod, null, obj_printer_settings, new object[] { "ShowPDF", "no"&