1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
private static void PrintPdf(string Path)
{
string value = null;
string commandPath = null;
string arguments = null;
RegistryKey regedit = null;
try
{
regedit = RegistryKey.OpenRemoteBaseKey(Microsoft.Win32.RegistryHive.ClassesRoot, "").OpenSubKey(".pdf");
value = System.Convert.ToString(regedit.GetValue(""));
if (value != null)
{
regedit = RegistryKey.OpenRemoteBaseKey(Microsoft.Win32.RegistryHive.ClassesRoot, "").OpenSubKey(value + @"\shell\printto\command");
value = System.Convert.ToString(regedit.GetValue(""));
if (value != null)
{
if (value.IndexOf("/") > 0)
commandPath = value.Substring(0, value.IndexOf("/"));
else
commandPath = value.Substring(0, value.IndexOf(" "));
arguments = value.Substring(commandPath.Length).Trim();
commandPath = commandPath.Replace("%SystemRoot%", System.Environment.GetEnvironmentVariable("SystemRoot")).Trim();
}
else
{
}
}
else
{
}
}
finally
{
if (regedit != null)
regedit.Close();
}
Process printer = new Process();
printer.StartInfo.UseShellExecute = true;
printer.StartInfo.CreateNoWindow = true;
printer.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
printer.StartInfo.Arguments = arguments.Replace("%1", Path).Replace("%2", Printer).Replace(" \"%3\"", string.Empty).Replace(" \"%4\"", string.Empty);
printer.StartInfo.FileName = commandPath;
printer.Start(); |
Partager