设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

123下一页
返回列表 发新帖
查看: 8900|回复: 25
打印 上一主题 下一主题

[模块/函数] [已解决]报表转pdf源码

[复制链接]
跳转到指定楼层
1#
发表于 2007-12-9 10:30:05 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
请问:
能在vba代码或宏中实现报表转换成pdf吗?
我有一个报表,要下发给多个单位,由于每个单位的内容各不相同(也即要针对每个单位生成一个pdf文件)。需在程序代码中批量生成pdf
由于装pdf虑拟打印机生成pdf文件中要提示录入文件名(如果屏蔽提示的话,又自动将多个打印文档合并成一个pdf),这样在生成pdf文档数量多的情况下,极不方便。
以前我生成snp时用的如下语句:
DoCmd.OutputTo acReport, "报表名", "SnapshotFormat(*.snp)", "snp文件名", False, "", 0
非常方便,但现在改用pdf后,有类似的代码吗?

经指点,在网内查到有生成pdf代码的程序(见附件)。
但有几点不明,请指教:
1、没怎么看懂该函数,不知结尾在哪里,是否要在最后两行:
DoCmd.OpenReport RptName, acViewPreview, , Wherecon
Reports(RptName).Visible = False

后加 end function
2、函数中描述的.dll文件是指的DynaPDF.dll StrStorage.dll吗?这两个都要下载,还是只下载一个就行了?
3dll文件在哪有下载的,能给个具体的链体地址吗?
4dll文件下载后是否放在mdb文件后在目录就行了
5ConvertReportToPDF函数怎么调用,能举个例吗?比如我的报表名为:rpt,要生成的pdf文件名为: c:\aa.pdf如针对以上给出ConvertReportToPDF函数的实例吗? 附件:chajiangliang兄的代码:[推荐]老外的+我的改進=直接生成完美的PDF報表Public Function ConvertReportToPDF( _
Optional RptName As String = "", _
Optional SnapshotName As String = "", _
Optional OutputPDFname As String = "", _
Optional ShowSaveFileDialog As Boolean = False, _
Optional StartPDFViewer As Boolean = True, _
Optional CompressionLevel As Long = 0, _
Optional PasswordOwner As String = "", _
Optional PasswordOpen As String = "", _
Optional PasswordRestrictions As Long = 0, _
Optional PDFNoFontEmbedding As Long = 0, Optional Wherecon As String) As Boolean


' RptName is the name of a report contained within this MDB
' SnapshotName is the name of an existing Snapshot file
' OutputPDFname is the name you select for the output PDF file
' ShowSaveFileDialog is a boolean param to specify whether or not to display
' the standard windows File Dialog window to select an exisiting Snapshot file
' CompressionLevel - not hooked up yet
' PasswordOwner - not hooked up yet
' PasswordOpen - not hooked up yet
' PasswordRestrictions - not hooked up yet
' PDFNoFontEmbedding - Do not Embed fonts in PDF. Set to 1 to stop the
' default process of embedding all fonts in the output PDF. If you are
' using ONLY - any of the standard Windows fonts
' using ONLY - any of the standard 14 Fonts natively supported by the PDF spec
'The 14 Standard Fonts
'All version of Adobe's Acrobat support 14 standard fonts. These fonts are always available
'independent whether they're embedded or not.
'Family name PostScript name Style
'Courier Courier fsNone
'Courier Courier-Bold fsBold
'Courier Courier-Oblique fsItalic
'Courier Courier-BoldOblique fsBold + fsItalic
'Helvetica Helvetica fsNone
'Helvetica Helvetica-Bold fsBold
'Helvetica Helvetica-Oblique fsItalic
'Helvetica Helvetica-BoldOblique fsBold + fsItalic
'Times Times-Roman fsNone
'Times Times-Bold fsBold
'Times Times-Italic fsItalic
'Times Times-BoldItalic fsBold + fsItalic
'Symbol Symbol fsNone, other styles are emulated only
'ZapfDingbats ZapfDingbats fsNone, other styles are emulated only


Dim s As String
Dim blRet As Boolean
' Let's see if the DynaPDF.DLL is available.
blRet = LoadLib()
If blRet = False Then
' Cannot find DynaPDF.dll or StrStorage.dll file
Exit Function
End If

On Error GoTo ERR_CREATSNAP
Dim strPath As String
Dim strPathandFileName As String
Dim strEMFUncompressed As String

Dim sOutFile As String
Dim lngRet As Long

' Init our string buffer
strPath = Space(Pathlen)

'Save the ReportName to a local var
mReportName = RptName

' Let's kill any existing Temp SnapShot file
If Len(mUncompressedSnapFile & vbNullString) > 0 Then
Kill mUncompressedSnapFile
mUncompressedSnapFile = ""
End If

' If we have been passed the name of a Snapshot file then
' skip the Snapshot creation process below
If Len(SnapshotName & vbNullString) = 0 Then

' Make sure we were passed a ReportName
If Len(RptName & vbNullString) = 0 Then
' No valid parameters - FAIL AND EXIT!!
ConvertReportToPDF = ""
Exit Function
End If

' Get the Systems Temp path
' Returns Length of path(num characters in path)
lngRet = GetTempPath(Pathlen, strPath)
' Chop off NULLS and trailing "\"
strPath = Left(strPath, lngRet) & Chr(0)

' Now need a unique Filename
' locked from a previous aborted attemp.
' Needs more work!
strPathandFileName = GetUniqueFilename(strPath, "SNP" & Chr(0), "snp")

' Export the selected Report to SnapShot format
DoCmd.Echo False
DoCmd.OpenReport RptName, acViewPreview, , Wherecon
Reports(RptName).Visible = False



[ 本帖最后由 cuxun 于 2007-12-12 09:20 编辑 ]
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏2 分享分享 分享淘帖 订阅订阅
2#
 楼主| 发表于 2007-12-9 17:03:41 | 只看该作者
十分感谢!!
不过能直接举个例吗,比如
比如我的报表名为:rpt,
要生成的pdf文件名为: c:\aa.pdf
怎样通过
ConvertUncompressedSnapsh???? 调用
生成,直接给出我的实例,十分感谢!!

还有就是.dll文件在哪下载?我搜了多次都没搜到
3#
 楼主| 发表于 2007-12-11 13:11:02 | 只看该作者
十分感谢!!
不过运行时提示"GetFunTempPath"没定义,不知是哪儿我没设置对
4#
发表于 2007-12-12 08:54:53 | 只看该作者
呵呵,收藏说不定那天能用到~谢谢cuxun
5#
发表于 2007-12-12 16:40:46 | 只看该作者
看看。。。。
6#
发表于 2008-1-27 12:47:15 | 只看该作者
牛,学习了!!!!!!!
7#
发表于 2008-1-31 14:10:15 | 只看该作者

謝謝CUXUN

謝謝   分享 , :handshake :handshake :handshake :handshake :handshake :handshake :handshake :handshake :handshake :handshake :handshake :handshake :handshake :handshake :handshake
8#
发表于 2008-2-1 14:04:50 | 只看该作者
谢谢CUXUN
能否将“dynapdf.dll"也上传。
9#
发表于 2008-2-1 17:42:02 | 只看该作者
好东西呀,不过没有测试,国外记得有个DLL控件,可以简单实现。
10#
发表于 2008-2-28 09:18:31 | 只看该作者
正需要这类的控件
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-6-8 17:20 , Processed in 0.104857 second(s), 35 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表