您的位置:首页 > 编程语言 > VB

VBA使用Acrobat Distiller生成PDF文件

2006-02-14 22:18 926 查看
原理如下:
1. 使用Acrobat Distiller打印激活worksheet or range生成postscript文件
2. 使用Acrobat Distiller API 将postscript转化成 .PDF 文件
 
首先,在VBA工程中引用Acrobat Distiller



然后,进行Acrobat Distiller的打印设置(必须,否则转化出错!)






将 Do not send fonts to "Adobe PDF" 选项钩选掉(不选)

 


代码:

        Public Sub MakePDF(ByVal strPDFFileName As String)
 
            ' Define the postscript and .pdf file names.
            Dim strPSFileName As String
 
            Dim xlWorksheet As Worksheet
            Dim objPdfDistiller As PdfDistiller
 
            strPSFileName = Left(strPDFFileName, InStrRev(strPDFFileName, "/")) & "tmpPostScript.ps"
 
            ' Print the Excel ActiveSheet to the postscript file
            Set xlWorksheet = ActiveSheet
            Call xlWorksheet.PrintOut(copies:=1, preview:=False, ActivePrinter:="Acrobat Distiller", printtofile:=True, collate:=True, prtofilename:=strPSFileName)
 
            ' Convert the postscript file to .pdf
            Set objPdfDistiller = New PdfDistiller
            Call objPdfDistiller.FileToPDF(strPSFileName, strPDFFileName, "")
 
            ' Finally, delete the postscript file
            Call Kill(strPSFileName)
 
        End Sub

 

程序调用的时候,需要修改Adobe PDF Settings的默认设置:

开始菜单  ⇒  设定  ⇒  打印机 ⇒  选择Adobe PDF,右键选属性 ⇒  选择"详细设定"选项卡 ⇒ 点击"标准设定"按钮 ⇒ 钩选掉"Do no send fonts to 'Adobe PDF'"

 

调用: Sub MakePDFApp() Call MakePDF("c:/firefox.pdf") End Sub 这样就能在指定位置生成指定的PDF文件了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息