-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpdftsfm.vbs
211 lines (174 loc) · 5.19 KB
/
pdftsfm.vbs
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
'********************************************
'Main
'*******************************************
if WScript.Arguments.Count < 2 then
wscript.quit
end if
input_file = WScript.Arguments(0)
ouput_file = WScript.Arguments(1)
'copy to temp file
f0 = WScript.ScriptFullName
Set fso = CreateObject("Scripting.FileSystemObject")
abs_path = fso.GetAbsolutePathName(f0 & "\..")
temp_file = abs_path & "\temp_file\" & (Replace(Time(),":","")) & "_" & GetFileName(input_file)
prn_file = abs_path & "\temp_file\" & (Replace(Time(),":","")) & "_prn.prn"
CopyFileTo input_file,temp_file
'choice the ext to transform
'make the ext into upper case
'dont open the source file , it make exception
'and we can open the temp file
file_ext = UCase(GetFileExt(input_file))
' WORD document
if file_ext = ".DOC" or file_ext = ".DOCX" then
a = doc2prn(temp_file,prn_file)
end if
'Excel document
if file_ext = ".XLS" or file_ext = ".XLSX" then
a = xls2prn(temp_file,prn_file)
end if
'PPT document
if file_ext = ".PPT" or file_ext = ".PPTX" then
a = ppt2prn(temp_file,prn_file)
end if
'after printer handle , we got the .prn file
'at last transform .prn to .pdf
Set shell=Wscript.createobject("wscript.shell")
ouput_file = replace(ouput_file,"\","/")
gscmd = abs_path & "\gs\transform_oncall.bat " & prn_file & " " & ouput_file & " " & abs_path & "\temp_file"
'msgbox gscmd
result = shell.run(gscmd,0)
'msgbox gscmd
'MsgBox GetFilePath(input_file)
'MsgBox GetFileExt(input_file)
'MsgBox GetFileName(input_file)
'(Int(Rnd()*100000) & Int(Rnd()*100000))
'sleep(1000)
'********************************************
'func
'c:\abc\566\123.txt c:\abc\566\456.txt
'*******************************************
Function CopyFileTo(f_from,f_to)
Set fso = Wscript.CreateObject("Scripting.FileSystemObject")
set c=fso.getfile(f_from) 'to copy
c.copy(f_to) 'to where
End Function
'********************************************
'func
'c:\abc\566\123.txt return c:\abc\566\
'*******************************************
Function GetFilePath(fp)
n = 0
ret = 0
do
'msgbox(Right(fp,n))
if Left(Right(fp,n),1) = "\" then
ret = 1
else
n=n+1
end if
loop until n = len(fp) - 1 or ret = 1
GetFilePath = Left(fp,len(fp) - n + 1)
End Function
'********************************************
'func
'c:\abc\566\123.txt return .txt
'*******************************************
Function GetFileExt(fp)
n = 0
ret = 0
do
'msgbox(Right(fp,n))
if Left(Right(fp,n),1) = "." then
ret = 1
else
n=n+1
end if
loop until n = len(fp) - 1 or ret = 1
GetFileExt = Right(fp,n)
End Function
'********************************************
'func
'c:\abc\566\123.txt return 123.txt
'*******************************************
Function GetFileName(fp)
n = 0
ret = 0
do
'msgbox(Right(fp,n))
if Left(Right(fp,n),1) = "\" then
ret = 1
else
n=n+1
end if
loop until n = len(fp) - 1 or ret = 1
GetFileName = Right(fp,n-1)
End Function
'********************************************
'func
'c:\abc\566\123.txt return 123.txt
'*******************************************
Function xls2prn(xls_file,prn_file)
On Error Resume Next
Set objApp = CreateObject("Excel.Application")
Set objDoc = objApp.Workbooks.Open (xls_file)
cols = objApp.ActiveSheet.UsedRange.Columns.Count
if cols < 10 then
objApp.ActiveSheet.PageSetup.PaperSize = 9
objApp.ActiveSheet.PageSetup.Zoom = 60
end if
if cols >= 10 and cols =<20 then
objApp.ActiveSheet.PageSetup.PaperSize = 9
objApp.ActiveSheet.PageSetup.Zoom = 60
end if
'msgbox cols
if cols >= 20 and cols =<30 then
objApp.ActiveSheet.PageSetup.PaperSize = 8
objApp.ActiveSheet.PageSetup.Zoom = 50
end if
if cols > 30 and cols =<50 then
objApp.ActiveSheet.PageSetup.PaperSize = 180
objApp.ActiveSheet.PageSetup.Zoom = 120
end if
'file_path = CreateObject("Scripting.FileSystemObject").GetFolder(".").Path
'file_path = file_path & "\" & "out.prn"
objApp.Sheets.PrintOut ,,1,,"InfoView Document Printer",1,True,prn_file,0
objDoc.Close True
set objApp=nothing
err.Clear
End Function
'********************************************
'func
'c:\abc\566\123.txt return 123.txt
'*******************************************
Function doc2prn(doc_file,prn_file)
Set objWD = CreateObject("Word.Application")
Set objDoc = objWD.Documents.Open(doc_file)
objWD.ActivePrinter = "InfoView Document Printer"
'file_path = CreateObject("Scripting.FileSystemObject").GetFolder(".").Path
'file_path = file_path & "\" & "out.prn"
'MsgBox prn_file
'Item 7 With MarkUP
'objWD.PrintOut 1,0,0,prn_file,,,7,1
objWD.PrintOut 1,0,0,prn_file,,,0,1
'objWD.PrintOut 1,0,0,prn_file,,,7,1,0,1,True,""
objDoc.Close
set objWD=nothing
End Function
'********************************************
'func
'c:\abc\566\123.txt return 123.txt
'*******************************************
Function ppt2prn(ppt_file,prn_file)
Set objPPT = CreateObject("PowerPoint.Application")
Set objDoc = objPPT.Presentations.Open(ppt_file, -1, 0, 0)
Set objOptions = objDoc.PrintOptions
objOptions.ActivePrinter = "InfoView Document Printer"
objOptions.PrintInBackground = 0
objDoc.PrintOut 1, 9999, prn_file, 1, 0
objDoc.Saved = 1
objDoc.Close
objPPT.Quit
Set objOptions = Nothing
Set objDoc = Nothing
Set objPPT = Nothing
End Function