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 52 53 54 55 56 57 58 59 60 61 62
|
private void Printpdf(string path)
{
string value = null;
//command path pour imprimer un pdf
string commandPath = null;
//argument pour la command path
string arguments = null;
//Ouverture de le BDR sur HKEY_CLASSES_ROOT\.pdf
RegistryKey regedit = null;
try
{
regedit = RegistryKey.OpenRemoteBaseKey(Microsoft.Win32.RegistryHive.ClassesRoot, "").OpenSubKey(".pdf");
// nom de l'application permettant de lire le PDF
value = System.Convert.ToString(regedit.GetValue(""));
if (value != null)
{
//ouverture de la BDR sur HKEY_CLASSES_ROOT\value\shell\printto\command
regedit = RegistryKey.OpenRemoteBaseKey(Microsoft.Win32.RegistryHive.ClassesRoot, "").OpenSubKey(value + @"\shell\printto\command");
//ligne de commande pour l'impression d'un pdf
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();
}
//Lancement de l'impression
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