致力于测试团队建设和自动化测试开发,欢迎有兴趣者一起研究讨论

将Word文件自动转换为Pdf格式文件脚本

上一篇 / 下一篇  2008-06-27 18:44:39 / 个人分类:QTP

51Testing软件测试网;~ e:v F2xbU$^.U'|

闲来无聊,尝试着写了个转换脚本,呵呵

6n}[.{w _7iBm051Testing软件测试网 Z5k)_*C2n-{q}

1、前置条件:51Testing软件测试网AuW c ~7[F

51Testing软件测试网#zs9O.}l;m/WaF8|

a)安装必须的工具MS Office2003,Adobe Acrobat 7.0Professional,postscrīpt.exe,gs811w32.exe

{0hxK2yp i^l0

;^4?(B S:m[v0postscrīpt.exe:是一个PDF转换时所需要的脚本51Testing软件测试网3ox^^,Qun

8Q9D[ B!WsY0gs811w32.exe:是一个PDF虚拟打印机的驱动

DX SD^i.dK$Mj0

Xr2]Z"h@"H-u0b)配置虚拟打印机

5A8QbKhlOY+Y~,n0

w"S ^WYOz |#J'^0进入Windows的控制面板,进入打印机,点击"添加打印机"图标.在安装对话框上按"下一步",出现选择打印机时,在制造商一栏中选择"Generic",在打印机一栏中,选择"MS Publisher Color Printer",然后一路按下一步,直到结束

1it'D5?g&Xl7n051Testing软件测试网0?/w @7g-ww

2、Code如下:

%R.QB"oessL051Testing软件测试网&Y8?$M#P1?G0| ff

Function WordToPdf(DocFile , PdfFile , Printer)
&S2VA l:j.YL|5H0 '函数功能:将WORD文件自动转换为PDF文件51Testing软件测试网 rc K$C7O8]]2^A
 '参数说明:51Testing软件测试网v5Da~pG J,{%{}
 'DocFile:需要被转换的DOC文件路径
&G"yF N%G\^-IS0 'PdfFile:转换后的PDF文件路径
KKjy'@0 'Printer:PDF虚拟打印机名称
5Zu;`"U Wm0 Dim PsFile '转换时所产生的PS脚本
Qu8REf7p0 Dim PsLogFile '转换时所产生的PS脚本日志文件51Testing软件测试网7M"N FHD;l3Ok
 51Testing软件测试网rs}}1Gc
 '建立对象51Testing软件测试网4e5V^ Nt
 Set ōWord = CreateObject("Word.Application")51Testing软件测试网exXX7bO:j I+P
 Set ōPdf = CreateObject("PDFDistiller.PDFDistiller.1")
,Pb lR|/h0 Set fso = CreateObject("scrīpting.FileSystemObject")
(D;FDl'D0 51Testing软件测试网8G0`LL4uZ:jK
 '获取临时文件名51Testing软件测试网sohLV
 Arr = Split(DocFile , ".")51Testing软件测试网/UD*p Q3x.OL~$C8D"g
 PsFile = Arr(0) & ".ps"51Testing软件测试网Tt"j,uE6FV$EII
 PsLogFile = Arr(0) & ".log"
xIhIhh*a0  
p!~Zv-Ty8U:?0 If fso.FileExists(PdfFile) Then
Nu5mF%]}T H x0  fso.DeleteFile PdfFile , True
NGa&{JhK0 End If
-W.R+CO+Z2yjX:q1K0 51Testing软件测试网?VF U*BO C
 '设置虚拟打印机51Testing软件测试网:ah$e;@&\J8]g
 oWord.ActivePrinter = Printer51Testing软件测试网qR8~-t:^(kLI
 51Testing软件测试网yV8}"d ]W_m"]
 '打开一个WORD文件51Testing软件测试网Zh?%Q{ }4}
 oWord.Documents.Open DocFile51Testing软件测试网%^h^?UwM
 
4n B@O+A+I0 '转化DOC文件为PS文件
v&xei#s|0 oWord.PrintOut False , False , 0 , PsFile51Testing软件测试网4W/k ~qrvu
 oWord.Documents.Close51Testing软件测试网#uvMdt._*Bh
 51Testing软件测试网 ic(^n'V
 '转化PS文件为PDF文件
ex~4fQ?K2d{iI0 oPdf.FileToPDF PsFile , PdfFile , ""
~w%_jQ1eG0 oWord.Quit
(]-W F |J&u8JTv0 
5BeJ%n KFu0 '删除PS和LOG文件
L(}/y x'b qhA1Gu,Q;X0 fso.GetFile(PsFile).Delete
0B us {y F0 fso.GetFile(PsLogFile).Delete
/e)vS j|&j0 
x:z2G!{7k5h#E0 '释放对象51Testing软件测试网/\\wu0H|;D(K+uy
 Set fso = Nothing
v+i^^fKD0 Set ōPdf = Nothing51Testing软件测试网v ]'C6E#^ QE%P7H5G
 Set ōWord = Nothing
cd"d~%ID'ssm0End Function

N(ZdS,A[051Testing软件测试网ryh"_)M^({.Y

 51Testing软件测试网&K)G!d5V%n{!rH


TAG: QTP

 

评分:0

我来说两句

日历

« 2024-04-27  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 91099
  • 日志数: 79
  • 图片数: 1
  • 建立时间: 2008-05-18
  • 更新时间: 2009-06-04

RSS订阅

Open Toolbar