Bonjour,
Est ce je peux imprimer un fichier connaissant son emplacement avec ASP.NET?
Version imprimable
Bonjour,
Est ce je peux imprimer un fichier connaissant son emplacement avec ASP.NET?
Tout dépends du type de fichier que c'est...
et surtout savoir si tu veux imprimer sur le serveur ou le client
Oui c'est possible aussi bien coté client que serveur.
Bon courage.
je veux imprimer un fichier PDF mis côté serveur sur une imprimante locale
Code:
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(); }
J'ai essayé ce code et ça fonctionne
Mais, si je met un fichier .PDF au lieu du .XLS , ça ne fonctionne pasCode:
1
2
3
4
5
6
7
8
9
10
11 Dim P As New System.Diagnostics.Process Dim FileName As String FileName = "C:\OK.pdf" P.StartInfo.FileName = FileName P.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden P.StartInfo.Verb = "PrintTo" P.StartInfo.Arguments = "HP LaserJet P1505n" P.StartInfo.CreateNoWindow = True P.Start()