[AccessD] Printing PDF files

Jim Dettman jimdettman at earthlink.net
Tue Apr 18 06:17:22 CDT 2006


Tom,

  I pretty much do the same (use on the fly printing for printer control),
but I use Ghost Script for the PDF.  Procedure is below.

Jim.

Function RunReportAsPDF(strReportName As String) As String

        ' Prints a report to disk
        ' and then converts to a PDF file with Ghost Script.
        ' Returns name of file if sucessfull
        ' empty string ("") if not.
        Const RoutineName = "RunReportAsPDF"
        Const Version = "1.0"
        
        Dim strPDFPrinter As String
        Dim strPDFProgPath As String
        Dim strPDFFileName As String
        Dim strPRNFile As String
        Dim lngHWnd As Long

10      On Error GoTo RunReportAsPDF_Error

20      RunReportAsPDF = ""

30      strPDFPrinter = GetAppConfigValue(AppShortName(), "PDFPrinter", ".",
".")
40      strPDFProgPath = GetAppConfigValue(AppShortName(), "PDFProgPath",
".", ".")
50      strPRNFile = GetAppConfigValue(AppShortName(), "PDFPrnFile ", ".",
".")

        ' Kill the printer output file if it already exists.
60      If (Dir(strPRNFile) & "" <> "") Then
70        On Error Resume Next
80        Kill strPRNFile
90        On Error GoTo RunReportAsPDF_Error
100     End If

        ' Now run the report
110     If SetDefaultPrinter(strPDFPrinter) = True Then
120       DoCmd.OpenReport strReportName, acViewNormal

          ' Wait until the report completes
130       Do While Dir(strPRNFile) & "" = ""
140         DoEvents
150       Loop

160       Call ResetDefaultPrinter(0)

          'Generate file name to use for PDF output
170       strPDFFileName = GetTempFileName_TSB(AppShortName())
180       strPDFFileName = Replace(strPDFFileName, ".tmp", ".pdf")
        
          ' Change printer driver output into a PDF
          ' Script the batch file
190       Open strPDFProgPath & "MKPDF.bat" For Output As #1
200       Print #1, "" & left(strPDFProgPath, 2)
210       Print #1, "" & "CD " & Chr(34) & Mid(strPDFProgPath, 3) & Chr(34)
220       Print #1, "" & Chr(34) & strPDFProgPath & "MAKEPDF" & Chr(34) & "
" & strPRNFile & " /D /V1.4 /O" & strPDFFileName
230       Close #1
        
          ' Execute batch file
240       strPDFProgPath = Chr(34) & strPDFProgPath & "MKPDF.bat" & Chr(34)
250       lngHWnd = Shell(strPDFProgPath, vbMinimizedNoFocus)
        
          ' and wait till done.
260       WaitWhileRunning (lngHWnd)
        
270       RunReportAsPDF = strPDFFileName
        
280     Else
290       gstrMBTitle = "Printer not installed."
300       gstrMBMsg = "The printer " & strPDFPrinter & " is not installed."
310       gstrMBMsg = gstrMBMsg & vbCrLf & "Please correct."
320       gintMBDef = vbCritical + vbOKOnly
330       gintMBBeep = True
340       gintMBLog = True
350       Call DisplayMsgBox
360       RunReportAsPDF = ""
370     End If

RunReportAsPDF_Exit:

380     Exit Function

RunReportAsPDF_Error:
390     UnexpectedError ModuleName, RoutineName, Version, Err.Number,
Err.Description, Err.Source, VBA.Erl
400     RunReportAsPDF = ""
410     Resume RunReportAsPDF_Exit

End Function 

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Tom Keatley
Sent: Monday, April 17, 2006 6:58 PM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Printing PDF files

John...
Whether it is any help or not.....

I have the same situation in that I have to produce invoices as a normal 
report (to a printer) and also produce a PDF copy which is then saved to a 
directory of my choosing on the fly

I have built this facility into code by.....

Having a table with a default printer field.

Changing the default printer to my PDF utility (after saving my default 
printer in my field).

I use Jaws Systems PDF writer although there are a LOT of these type of 
programs .
Although I dont need it I believe the JAWS PDF utility will allow you via 
code to specify a directory as part of the command just as it allows you to 
name the file ....

I then print the report to PDF which will be saved in the default directory 
I have set up for it.
The file name is actually the caption property of the report.
Then change back to the previous default printer and print the report to the

printer

As far as the users are concerned it is pretty transparent ...all they see 
is the print dialog come up for a sec while it is writing to the PDF file 
and then theys see the next dialog come up for the printer report...

I use a printer class from ATTAC Consulting   (On the fly printing? I think)

to handle all printing requirements although that was because I lacked the 
abilities to use printer API's properly myself (which you probably dont)

I can send you code snippets if you need them

REgards

Tom Keatley




----- Original Message ----- 
From: "John Colby" <jwcolby at ColbyConsulting.com>
To: "'Access Developers discussion and problem solving'" 
<accessd at databaseadvisors.com>
Sent: Monday, April 17, 2006 8:00 PM
Subject: Re: [AccessD] Printing PDF files


> Stuart,
>
> I need to actually build a file name and have each report save to that
> custom directory as it is printed - all automatically.  I was able to do
> that with the solution I chose but for some reason the printer driver
> started hanging - at the worst possible time, over the weekend with no 
> tech
> support when the client REALLY needed to be working.
>
> So in a nutshell, I need to be able to write code to cause the print of 
> the
> report to go to a specific directory, determined at the instant the print
> happens.
>
>
>
> John W. Colby
> www.ColbyConsulting.com
>
>
> -----Original Message-----
> From: accessd-bounces at databaseadvisors.com
> [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Stuart 
> McLachlan
> Sent: Friday, April 14, 2006 7:36 PM
> To: Access Developers discussion and problem solving
> Subject: Re: [AccessD] Printing PDF files
>
> On 14 Apr 2006 at 17:52, John Colby wrote:
>
>> What is involved in printing reports to adobe PDF files using the full
>> on adobe package?  My client got it and I need to mod my program to
>> print to this.
>>
>
> Installing the full Adobe creates a printer called "Adobe PDF". It's just 
> a
> case of setting the report to print to that specific printer instead of 
> the
> default printer.
>
> By default, Adobe  is set up to request a file name when you create the
> document.
>
> If you want to automate printing with no user intervention, you need to
> change the option "Prompt for Adobe Filename" in the printer properties
> under "General - Printing Preferences... - Adobe PDF Settings"
> In this case the PDF  will be printed into the default directory for the
> printer and will have the same name as the report plus a .PDF extension.
> The Default directory is specified under "Properties - Ports" for the
> printer.
>
> If you want the reports saved to a different directory, you need to set up
> another copy of the printer with a different default directory.
>
> If you want a different name for the file, you need to make a copy of the
> report with an appropriate name, print that copy and then delete it.
>
> Something like:
> strReportName = "DailyReport" & Format$(Date(),"yymmdd") Docmd.CopyObject
> ,strReportName,acReport,"rptDailyReport"
> Docmd.Open strReportName
> Docmd.DeleteObject acReport,strReportName
>
> --
> Stuart
>
>
> -- 
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>
> -- 
> AccessD mailing list
> AccessD at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>
>
> -- 
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.1.385 / Virus Database: 268.4.2/314 - Release Date: 16/04/2006
>
>
>
> -- 
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.1.385 / Virus Database: 268.4.2/314 - Release Date: 16/04/2006
>
> 

-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com





More information about the AccessD mailing list