"John" <jo**@nospam.infovis.co.uk> wrote in message news:<40*********************@news-text.dial.pipex.com>...
Hi
Is there a way to create pdf of reports from within access?
Thanks
Regards
This is a great idea. Basic reports have all the information
available such as text box locations and fonts. One problem is that
many of the fonts used in reports are not standard PostScript fonts
and will entail dealing with embedding fonts. There is no legal issue
since the report will not be edited in e.g., Acrobat later. If you
want to do things like Centering, Left or Right justification then it
will be necessary to know how much room your font is going to take up.
If there is not a lot of kerning (typical) then using the Font Metrics
for the given font will give you a good approximation to the space
used by the string. Font Metrics can usually be found in the font's
..afm file. For reasons I won't go into now, the .afm file is not
always easy to come by so an empirical approach may be required to get
the character widths. The following function is an example:
Public Function GetFontWidth(strIn As String, strFontName As String,
dblFontSize As Double) As Double
Dim lngTemp As Long
Dim MetricRS As Recordset
Dim MyDB As Database
Dim strSQL As String
Dim intI As Integer
Dim strChar As String
Dim lngASC As Long
GetFontWidth = 0#
If Len(strIn) = 0 Then Exit Function
lngTemp = 0
Set MyDB = CurrentDb
strSQL = "SELECT * FROM tbl" & strFontName & "Metrics;"
Set MetricRS = MyDB.OpenRecordset(strSQL, dbOpenSnapshot)
For intI = 1 To Len(strIn)
strChar = Mid(strIn, intI, 1)
lngASC = Asc(strChar)
MetricRS.FindFirst "[ASCIINumber] = " & CStr(lngASC)
If Not MetricRS.NoMatch Then
lngTemp = lngTemp + MetricRS("Width")
End If
Next intI
MetricRS.Close
Set MetricRS = Nothing
Set MyDB = Nothing
GetFontWidth = lngTemp * dblFontSize / 1000#
End Function
It can be called like:
dblFontWidth = GetFontWidth(Nz(txtPhone.Value, ""), "HelveticaBold",
9.5)
Then you would use the x coordinate of the center of the box minus
dblFontWidth / 2 in your centering function.
Note that pdf strings need to have certain characters transformed in
order to be printed out literally:
Function TLit(strIn As String) As String
Dim strTemp As String
Dim intI As Integer
Dim strChar As String
'Transform Literals
TLit = ""
If Len(strIn) = 0 Then Exit Function
For intI = 1 To Len(strIn)
strChar = Mid(strIn, intI, 1)
Select Case strChar
Case "\":
strTemp = strTemp & "\\"
Case "(":
strTemp = strTemp & "\("
Case ")":
strTemp = strTemp & "\)"
Case Else
strTemp = strTemp & strChar
End Select
Next intI
TLit = strTemp
End Function
Non-linearized pdf files can be generated from scratch directly in
Access using strings. Linearized pdf files can also be done using
strings if you are judicious about which end is used for appending.
If you are going to roll your own pdf files plan on spending at least
a few months. My priority is to get this done in a more OOP way by
creating pdf object type definitions in VBA that, among other things,
allow them to link to each other and allow an easy way to calculate
their size. After that is done I will take a serious look at writing
something that will automatically convert an Access Report into a set
of function calls that will create a pdf file. I have already done
some ad hoc reports that fill in an arbitrary number of rows from a
recordset onto pdf pages including text justification and word wrap.
I see no reason why the routines I've mentioned cannot be placed in a
DLL. Unfortunately, these plans will take some time and will not
solve your problem for awhile.
James A. Fortune