Attachment 'scriptblock.txt'
Download 1 <!-- PostScript-to-PDF Code block -->
2 <!-- -->
3
4 <msxsl:script language="C#" implements-prefix="wwdistpdf">
5 <![CDATA[
6
7
8 public bool FileToPDF(string ParamPostScriptFilePath,
9 string ParamPDFFilePath,
10 string ParamPDFOptions)
11 {
12 bool VarResult = false;
13
14 if (System.IO.File.Exists(ParamPostScriptFilePath))
15 {
16 string VarParentDirectoryPath;
17
18 // Create parent directories as needed
19 //
20 VarParentDirectoryPath = System.IO.Path.GetDirectoryName(ParamPDFFilePath);
21 while (( ! String.IsNullOrEmpty(VarParentDirectoryPath)) &&
22 ( ! System.IO.Directory.Exists(VarParentDirectoryPath)))
23 {
24 System.IO.Directory.CreateDirectory(VarParentDirectoryPath);
25
26 VarParentDirectoryPath = System.IO.Path.GetDirectoryName(VarParentDirectoryPath);
27 }
28
29 // Parent directory exists?
30 //
31 VarParentDirectoryPath = System.IO.Path.GetDirectoryName(ParamPDFFilePath);
32 if (System.IO.Directory.Exists(VarParentDirectoryPath))
33 {
34 object VarDistillerInstance = null;
35
36 try
37 {
38 Type VarDistillerType;
39
40 // Instantiate the COM object using late binding
41 //
42 VarDistillerType = Type.GetTypeFromProgID("PDFDistiller.PDFDistiller.1", true);
43 VarDistillerInstance = System.Activator.CreateInstance(VarDistillerType);
44 if (VarDistillerInstance != null)
45 {
46 object VarMethodResult;
47 long VarOriginalSpoolJobs;
48 long VarSpoolJobs;
49 short VarMethodResultAsInt16;
50
51 // Disable job spooling
52 //
53 VarMethodResult = VarDistillerType.InvokeMember("bSpoolJobs",
54 System.Reflection.BindingFlags.GetProperty,
55 null,
56 VarDistillerInstance,
57 null);
58 VarOriginalSpoolJobs = Convert.ToInt32(VarMethodResult);
59 VarSpoolJobs = 0;
60 VarMethodResult = VarDistillerType.InvokeMember("bSpoolJobs",
61 System.Reflection.BindingFlags.SetProperty,
62 null,
63 VarDistillerInstance,
64 new object[]{VarSpoolJobs});
65
66 // Invoke PostScript to PDF VarMethod
67 //
68 VarMethodResult = VarDistillerType.InvokeMember("FileToPDF",
69 System.Reflection.BindingFlags.InvokeMethod,
70 null,
71 VarDistillerInstance,
72 new object[]{ParamPostScriptFilePath, ParamPDFFilePath, ParamPDFOptions});
73 VarMethodResultAsInt16 = Convert.ToInt16(VarMethodResult);
74 if (VarMethodResultAsInt16 < 0)
75 {
76 // Error during PDF generation!
77 //
78 }
79 else if (VarMethodResultAsInt16 == 0)
80 {
81 // Invalid parameters!
82 //
83 }
84 else // (VarMethodResultAsInt16 > 0)
85 {
86 // Success!
87 //
88 VarResult = true;
89 }
90
91 // Restore original job spooling setting
92 //
93 VarMethodResult = VarDistillerType.InvokeMember("bSpoolJobs",
94 System.Reflection.BindingFlags.SetProperty,
95 null,
96 VarDistillerInstance,
97 new object[]{VarOriginalSpoolJobs});
98 }
99 }
100 catch
101 {
102 // Nothing to do!
103 //
104 }
105 finally
106 {
107 // Clean up COM object
108 //
109 if (VarDistillerInstance != null)
110 {
111 System.Runtime.InteropServices.Marshal.ReleaseComObject(VarDistillerInstance);
112 }
113 }
114 }
115 }
116
117 return VarResult;
118 }
119 ]]>
120
121 </msxsl:script>
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.