Results 1 to 13 of 13

Thread: [RESOLVED] Print too acrobat distiller from Crystal reports 8.5

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Indiana
    Posts
    612

    [RESOLVED] Print too acrobat distiller from Crystal reports 8.5

    Hello everyone. I have a cyrstal report embeded in my visual basic 6.0 program.

    I want to be able to print to a pdf file to a specific file name. Does anyone have any code, or a link they can point me to that will show me how to do this?

    I have Acrobat Distiller installed on my computer.

    Thanks
    Last edited by indydavid32; May 21st, 2003 at 08:06 AM.
    David Wilhelm

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Indiana
    Posts
    612

    Unhappy Bump

    Anyone?
    David Wilhelm

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Indiana
    Posts
    612

    Question Bump

    Anyone at all? I really need this....

    Thanks
    David Wilhelm

  4. #4
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    VB Code:
    1. Printer.DeviceName = "Acrobat Distiller"

    Does this work?
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Indiana
    Posts
    612

    Does not change the Cyrstal report printer

    No, this does not change the crystal report printer. I tried this. I need to be able to change the crystal report printer to the Acrobat Distiller, then have it save to a certain file name without prompting the user.

    I need the code that does this. I haven't been able to find it in here or the Seagate knowldge base web site.

    Thanks
    David Wilhelm

  6. #6
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    I use this to do it in using the PDFWriter driver...

    VB Code:
    1. FILE1 = "C:\INVENTORY REPORT - IN-USE EQUIPMENT FOR " & Me.Combo1.Text & ".pdf"
    2.    
    3.     ' CREATE THE PDF DOCUMENT
    4.    
    5.     Call WRITEINI("Acrobat PDFWriter", "pdffilename", FILE1, _
    6.         "C:\winnt\system32\spool\drivers\w32x86\2\__PDF.INI")
    7.  
    8. ' Code to print...

    This creates the name for me without user intervention...
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Indiana
    Posts
    612

    Hmmm...

    Does this change the name of an existing pdf file to a new name?

    If that's the case, that's not what I'm trying to do.

    I'm trying to create a crystal report within my vb project, which I do, then take that open crystal report and save it to a pdf file.

    Thanks!
    David Wilhelm

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Indiana
    Posts
    612

    Code

    In case this might help, this is my code.

    Code:
    Screen.MousePointer = vbHourglass
    CRViewer1.ReportSource = Report
    Report.Database.Tables(1).SetLogOnInfo "202.101.8.107", "Monthly Invoices", "sa", ""
    CRViewer1.ReportSource = Report
    
    CRViewer1.ViewReport
    CRViewer1.Zoom 90
    Screen.MousePointer = vbDefault
    However, instead of the user viewing the report, I want to save it as C:\Statement.pdf.

    Thanks
    David Wilhelm

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Indiana
    Posts
    612

    Unhappy bump

    bump
    David Wilhelm

  10. #10
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492

    Re: bump

    Originally posted by indydavid32
    bump
    bump?

    Jon

  11. #11
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492

    Re: bump

    VB Code:
    1. Option Compare Database
    2.  
    3. Option Explicit
    4.  
    5.    Public Const REG_SZ As Long = 1
    6.    Public Const REG_DWORD As Long = 4
    7.  
    8.    Public Const HKEY_CLASSES_ROOT = &H80000000
    9.    Public Const HKEY_CURRENT_USER = &H80000001
    10.    Public Const HKEY_LOCAL_MACHINE = &H80000002
    11.    Public Const HKEY_USERS = &H80000003
    12.  
    13.    Public Const ERROR_NONE = 0
    14.    Public Const ERROR_BADDB = 1
    15.    Public Const ERROR_BADKEY = 2
    16.    Public Const ERROR_CANTOPEN = 3
    17.    Public Const ERROR_CANTREAD = 4
    18.    Public Const ERROR_CANTWRITE = 5
    19.    Public Const ERROR_OUTOFMEMORY = 6
    20.    Public Const ERROR_ARENA_TRASHED = 7
    21.    Public Const ERROR_ACCESS_DENIED = 8
    22.    Public Const ERROR_INVALID_PARAMETERS = 87
    23.    Public Const ERROR_NO_MORE_ITEMS = 259
    24.  
    25.    Public Const KEY_QUERY_VALUE = &H1
    26.    Public Const KEY_SET_VALUE = &H2
    27.    Public Const KEY_ALL_ACCESS = &H3F
    28.  
    29.    Public Const REG_OPTION_NON_VOLATILE = 0
    30.    
    31.    Private drexisting As aht_tagDeviceRec
    32.            Const AcrobatName = "FinePrint pdfFactory Pro"
    33.            'Const AcrobatName = "FinePrint pdfFactory"
    34.            Const AcrobatDriver = "PDFWRITR"
    35.            Const AcrobatPort = "LPT1:"
    36.  
    37.    Declare Function RegCloseKey Lib "advapi32.dll" _
    38.    (ByVal hKey As Long) As Long
    39.    Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias _
    40.    "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
    41.    ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions _
    42.    As Long, ByVal samDesired As Long, ByVal lpSecurityAttributes _
    43.    As Long, phkResult As Long, lpdwDisposition As Long) As Long
    44.    Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias _
    45.    "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
    46.    ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As _
    47.    Long) As Long
    48.    Declare Function RegQueryValueExString Lib "advapi32.dll" Alias _
    49.    "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As _
    50.    String, ByVal lpReserved As Long, lpType As Long, ByVal lpData _
    51.    As String, lpcbData As Long) As Long
    52.    Declare Function RegQueryValueExLong Lib "advapi32.dll" Alias _
    53.    "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As _
    54.    String, ByVal lpReserved As Long, lpType As Long, lpData As _
    55.    Long, lpcbData As Long) As Long
    56.    Declare Function RegQueryValueExNULL Lib "advapi32.dll" Alias _
    57.    "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As _
    58.    String, ByVal lpReserved As Long, lpType As Long, ByVal lpData _
    59.    As Long, lpcbData As Long) As Long
    60.    Declare Function RegSetValueExString Lib "advapi32.dll" Alias _
    61.    "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _
    62.    ByVal Reserved As Long, ByVal dwType As Long, ByVal lpValue As _
    63.    String, ByVal cbData As Long) As Long
    64.    Declare Function RegSetValueExLong Lib "advapi32.dll" Alias _
    65.    "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _
    66.    ByVal Reserved As Long, ByVal dwType As Long, lpValue As Long, _
    67.    ByVal cbData As Long) As Long
    68.    Global g_OpSys As String
    69.    Public Function SetValueEx(ByVal hKey As Long, sValueName As String, lType As Long, vValue As Variant) As Long
    70.        Dim lValue As Long
    71.        Dim sValue As String
    72.        Select Case lType
    73.            Case REG_SZ
    74.                sValue = vValue & Chr$(0)
    75.                SetValueEx = RegSetValueExString(hKey, sValueName, 0&, lType, sValue, Len(sValue))
    76.            Case REG_DWORD
    77.                lValue = vValue
    78.                SetValueEx = RegSetValueExLong(hKey, sValueName, 0&, lType, lValue, 4)
    79.            End Select
    80.    End Function
    81.    Function QueryValueEx(ByVal lhKey As Long, ByVal szValueName As _
    82.    String, vValue As Variant) As Long
    83.        Dim cch As Long
    84.        Dim lrc As Long
    85.        Dim lType As Long
    86.        Dim lValue As Long
    87.        Dim sValue As String
    88.  
    89.        On Error GoTo QueryValueExError
    90.  
    91.        ' Determine the size and type of data to be read
    92.        lrc = RegQueryValueExNULL(lhKey, szValueName, 0&, lType, 0&, cch)
    93.        If lrc <> ERROR_NONE Then Error 5
    94.  
    95.        Select Case lType
    96.            ' For strings
    97.            Case REG_SZ:
    98.                sValue = String(cch, 0)
    99.  
    100.    lrc = RegQueryValueExString(lhKey, szValueName, 0&, lType, sValue, cch)
    101.                If lrc = ERROR_NONE Then
    102.                    vValue = Left$(sValue, cch - 1)
    103.                Else
    104.                    vValue = Empty
    105.                End If
    106.            ' For DWORDS
    107.            Case REG_DWORD:
    108.    lrc = RegQueryValueExLong(lhKey, szValueName, 0&, lType, lValue, cch)
    109.                If lrc = ERROR_NONE Then vValue = lValue
    110.            Case Else
    111.                'all other data types not supported
    112.                lrc = -1
    113.        End Select
    114.  
    115. QueryValueExExit:
    116.        QueryValueEx = lrc
    117.        Exit Function
    118.  
    119. QueryValueExError:
    120.        Resume QueryValueExExit
    121.    End Function
    122. Public Sub SetKeyValue(sKeyName As String, sValueName As String, vValueSetting As Variant, lValueType As Long)
    123.        Dim lRetVal As Long         'result of the SetValueEx function
    124.        Dim hKey As Long            'handle of open key
    125.  
    126.        'open the specified key
    127.        lRetVal = RegOpenKeyEx(HKEY_CURRENT_USER, sKeyName, 0, KEY_SET_VALUE, hKey)
    128.        lRetVal = SetValueEx(hKey, sValueName, lValueType, vValueSetting)
    129.        RegCloseKey (hKey)
    130.    End Sub
    131.            Sub ResetDefaultPrinter()
    132.                    Call ahtSetDefaultPrinter(drexisting)
    133.            End Sub
    134.            Function ChangeToAcrobat()
    135.                If ahtGetDefaultPrinter(drexisting) Then
    136.                    Dim dr As aht_tagDeviceRec
    137.                    With dr
    138.                        .drDeviceName = AcrobatName
    139.                        .drDriverName = AcrobatDriver
    140.                        .drPort = AcrobatPort
    141.                    End With
    142.                    Call ahtSetDefaultPrinter(dr)
    143.               End If
    144.            End Function
    145.            Sub ChangePdfFileName(NewFileName As String)
    146.               Call aht_apiWriteProfileString("Acrobat PDFWriter", "PDFFileName", NewFileName)
    147.            End Sub
    148. Function SetupPdfForPrint(ByVal sReportFile As String, ByVal keyVal) 'FOR WINDOWS NT/2000 PDF PRINTING
    149. '- Updates the registry for the correct pdffilename
    150. '- also sets bExecViewer = 0 just in case
    151. '  (so the Acrobat program is not launched after the file is created)
    152.     'SetKeyValue "Software\Adobe\Acrobat PDFWriter", "bExecViewer", "0", REG_SZ
    153.     'SetKeyValue "Software\Adobe\Acrobat PDFWriter", "PDFFileName", sReportFile, REG_SZ
    154.     'SetKeyValue "Software\FinePrint Software\pdfFactory", "bExecViewer", "0", REG_SZ
    155.     'SetKeyValue "SOFTWARE\FinePrint Software\pdfFactory", "PDFFileName", sReportFile, REG_SZ
    156.     SetKeyValue "Software\FinePrint Software\pdfFactory\FinePrinters\FinePrint pdfFactory Pro\PrinterDriverData", "ShowDlg", keyVal, REG_DWORD
    157.     SetKeyValue "Software\FinePrint Software\pdfFactory", "OutputFile", sReportFile, REG_SZ
    158. End Function
    159. Function ResetKeyValue(ByVal keyVal)
    160. 'this function resets the dialog box that pops up for fine print
    161. 'pdf factory.  By reset we mean the dialog box does NOT come up
    162. 'if the key value is 0 the dialog box comes on
    163. 'if the key value is 4 the dialog box disappears
    164. SetKeyValue "Software\FinePrint Software\pdfFactory\FinePrinters\FinePrint pdfFactory Pro\PrinterDriverData", "ShowDlg", keyVal, REG_DWORD
    165. End Function
    166. Function GetOpSys()
    167.     GetOpSys = g_OpSys
    168.  End Function

    VB Code:
    1. 'to print
    2. If Me.frameProjects.Value = 1 Then
    3.      'open issues report
    4.      rptName = "rptFOPL816"
    5.      ChangeToAcrobat 'MAKES pdf WRITER YOUR DEFAULT PRINTER
    6.      'second argument for key value.  0 turns on the dialog box
    7.      SetupPdfForPrint "FOPL816", 0
    8.      'ENTER TO PRINT 'THIS IS THE REPORT YOU WANT TO PRINT TO A PDF
    9.      
    10.      ResetDefaultPrinter 'RETURNS YOUR ORIGINAL PRINTER AS DEFAULT
    11.      ResetKeyValue 4     'reset the dialog box so it doesnt come on
    12.      Exit Sub
    13.   End If

    Note this involves modifying the registry via code..since the default printer needs to be changed to the acrobat distiller. I used fineprint..but as you see in the comments this works for adobe as well.

    Jon

    P.S: CR 9.0 supports ADOBE PDF output..maybe its worth the update?

  12. #12
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    Here is some sample code I use to export a report to a PDF disk file (version 8.5).

    VB Code:
    1. Dim objCrstal as CRAXDRT.Application
    2. Dim objReport As CRAXDRT.Report
    3. Dim objExportOptions As CRAXDRT.ExportOptions
    4.    
    5. Set objCrystal = New CRAXDRT.Application
    6.  
    7. Set objReport = objCrystal.OpenReport(strReportPath, 0)    
    8. Set objExportOptions = objReport.ExportOptions
    9.    
    10. With objExportOptions
    11.     .DestinationType = crEDTDiskFile
    12.     .DiskFileName = strExportLocation
    13.     .FormatType = crEFTPortableDocFormat
    14.     .PDFExportAllPages = True
    15. End With
    16.    
    17. objReport.Export False
    18.  
    19. Set objReport = Nothing
    20. Set objCrystal = Nothing

    I have no idea what Acrobat Distiller is or how it works but if it's a printer could you not use the Report.SelectPrinter method.

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Indiana
    Posts
    612

    Thumbs up Thank you thank you thank you thank you thank you

    Thank you very much Bruce. This works great. Exactly what I needed. I knew if I kept bugging you guys I would get the answer I needed. lol
    David Wilhelm

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width