Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

save report as PDF using Adobe Distiller

Status
Not open for further replies.

HomeGrowth

Technical User
Aug 19, 2004
76
US
I used original code from faq703-2533 and it works great with PDFWriter. I tried to modify three lines to use Acrobat Distiller. see below

Public Sub SaveReportAsPDF(strReportName As String, strPath As String)

Dim strOldDefault As String

strOldDefault = QueryKey("Software\Microsoft\Windows NT\CurrentVersion\Windows", "Device")

'Change the printer name from PDFWriter to Distiller
SetKeyValue "Software\Microsoft\Windows NT\CurrentVersion\Windows", "Device", "Acrobat PDFWriter", REG_SZ
'SetKeyValue "Software\Microsoft\Windows NT\CurrentVersion\Windows", "Device", "Acrobat Distiller", REG_SZ

SetKeyValue "Software\Adobe\Acrobat PDFWriter", "PDFFilename", strPath, REG_SZ
'SetKeyValue "Software\Adobe\Acrobat Distiller", "PDFFilename", strPath, REG_SZ

SetKeyValue "Software\Adobe\Acrobat PDFWriter", "bExecViewer", 0, REG_SZ
'SetKeyValue "Software\Adobe\Acrobat Distiller", "bExecViewer", 0, REG_SZ

DoCmd.OpenReport strReportName

SetKeyValue "Software\Microsoft\Windows NT\CurrentVersion\Windows", "Device", strOldDefault, REG_SZ

End Sub

It doesn't work silently behind the scene, but popping the 'Save As' window. What other areas I need to modify in order to get the Distiller to work instead the PDFWriter. Please share your insight if you have successfully modify this one to work with Acrobat Distiller. Thanks!
 
Man I piddled around for what seemed like forever trying to get the Distiller to work in line with Access. I finally broke down and purchased the Acrobat 6 SDK from Adobe($99). This eliminates the problem of the file dialogue and other nasty irritations like temporarily resetting a default printer and then setting it back programatically. If you use their library the code is short, sweet and foolproof. You just deposit your report into a watched folder and then call a routine like the one below to run it throught the distiller. No popups....just does the conversion and puts the resulting .pdf in the pickup folder. The main catch is writing out an Access report in a postscript format. I created a printer with a postscript driver and set it's port as the full path of a file in the folder that the distiller is configured to watch. I also set the report to use a specific printer....the one mentioned in the previous sentence. This can also be set a run time....

DoCmd.OpenReport ReportName:="rptPurchaseOrder", View:=acViewPreview

Set rpt = reports!rptPurchaseOrder
rpt.Printer = Application.Printers("PSFilePrinterColor")
DoCmd.Close acReport, "rptPurchaseOrder"
DoCmd.OpenReport "rptPurchaseOrderEmail", acViewNormal


Since the report is set to the specific printer and the printer is set up to print to a file in a sepcific folder the code above gets a post script report file into the Distiller watched folder. All that's left is code to run it through the Distiller and clean up the watched folder.....


Public Sub MakePDF(sFileIn As String, sFileOut As String)
On Error GoTo resume next

Dim pdf As New PdfDistiller6
Dim iResult As Integer

iResult = pdf.FileToPDF(sFileIn, sFileOut, "")

If iResult = 1 Then
Kill sFileIn
Else
MsgBox "Error creating PDF.", vbOKOnly, "PDF Creation Error"
End If

Exit Sub


Now just do whatever you want with the completed .pdf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top