Solved

VB6 and CR 8.5 - Generate multiple PDF's from a single report

Posted on 2010-11-24
6
892 Views
Last Modified: 2012-05-10
Hello all,

I've been looking all around for an answer to this question, so I figured I'd come to the experts instead of wasting any more time.  I've got a VB6 application in which I am generating a PDF export of a Crystal Reports 8.5 report.  This part is working "flawlessly", but I've been tasked with finding a way to actually generate SEPARATE PDF's for each page of that report, instead of one single PDF.  Here are the two main problems I'm running into:

1) I'd simply do a loop through each record and generate the individual PDF's, but my data source may contain multiple records for a single page of the report.  That, of course, means that, in certain circumstances, I'd end up with multiple pages where there should only be one.

2) I could manually split the PDF once it has been created, but the file creation and handling is taken care of by another department, and I really need this to be an automated process.

So, my primary question at this point is this: Is there a way through the VB6 code to do one of the following:

A) Get the actual number of pages that will be in the PDF (NOT the number of records in the recordset).  This way I can do a loop with that count as my maximum value, and generate each page individually using the PDFFirstPageNumber and PDFLastPageNumber properties to generate each page as its own PDF file.

B) Tell the Crystal Reports DLL to split the pages automatically.  I can't find any methods or properties in the DLL that appear to make that happen.

C) Other suggestions for how to best make this work...

Thanks for your time, experts.  Your assistance is greatly appreciated.  Here's a sample of the code I'm using for the PDF creation:

        Dim Viewer As CRAXDDRT.Application
        Dim Report As CRAXDDRT.Report
        Dim CRXData As CRAXDDRT.Database
        
        Set Viewer = New CRAXDDRT.Application
        Set Report = Viewer.OpenReport(AppInfo.ReportPath & "ReportFile.rpt", 1)
        
        Set CRXData = Report.Database
        
        CRXData.Tables(1).Location = PATH
        CRXData.SetDataSource rPolicy, 3, 1
        
        ' *********************************************************************
        ' ** Generate a PDF copy of the report, then display it for the user **
        ' *********************************************************************
        Report.ExportOptions.FormatType = crEFTPortableDocFormat
        Report.ExportOptions.DestinationType = crEDTDiskFile
        Report.ExportOptions.DiskFileName = AppInfo.ArchivePath & "Report " & Format(DateOfPolicy, "yyyymmdd") & ".pdf"
        Report.ExportOptions.PDFExportAllPages = True
        Report.Export False

Open in new window

0
Comment
Question by:khufford19
  • 3
  • 2
6 Comments
 
LVL 19

Expert Comment

by:GJParker
ID: 34206601
It's been a while since I looked at this sort of thing but from memory most PDF splitters run on the principal of running and exporting the report multiple times based on a group in the report.

Certainly in Version 8.5 I don't think it is possible to do what you want although there may be moer functionality in the newer versions.

Good Luck
0
 

Author Comment

by:khufford19
ID: 34207414
Well, I thought I had a solution using the GetReportVariableValue("TotalPageCount") method of the Report object, but when I tried to actually read the property, I got a "Permission Denied" error.  I even tried throwing that value into a different formula field in the report file itself, but I got the same error.  Well, it was worth a shot, anyway.

I suppose my next step is going to probably be to loop through my original recordset, then create a smaller "temporary" recordset based on the original identifier, and generate each one of those as individual reports.

@GJ - Thanks for the words of encouragement.  Somehow I just "assumed" that something like this would be much simpler.  Well, we all know what we get when we assume...
0
 
LVL 14

Accepted Solution

by:
Brook Braswell earned 500 total points
ID: 34207627
When your report is generated you can get the number of total pages with the PrintingStatus property

dim New_APP as NEW craxdrt.Application
dim New_Report as CRAXDRT.Report
Set New_Report = New_App.OpenReport("YourReport.rpt",1)

' set your report parameters...

dim nPages as long
nPages = New_Report.PrintingStatus.NumberOfPages




0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 14

Expert Comment

by:Brook Braswell
ID: 34207756
                              Dim nPages As Long
                               Dim cPage As Single
                               nPages = New_Report.PrintingStatus.NumberOfPages
                               For cPage = 1 To nPages
                                   New_Report.ExportOptions.PDFExportAllPages = False
                                   New_Report.ExportOptions.PDFFirstPageNumber = cPage
                                   New_Report.ExportOptions.PDFLastPageNumber = cPage
                                   New_Report.ExportOptions.DestinationType = crEDTDiskFile
                                   New_Report.ExportOptions.DiskFileName = App.Path & "\OutPut\REPORT_PAGE" & Format(cPage, "00") & ".pdf"
                                   New_Report.ExportOptions.FormatType = crEFTPortableDocFormat
                                   New_Report.DisplayProgressDialog = False
                                   New_Report.Export False
                                   
                               Next
                               MsgBox "EXPORT OF ALL " & nPages & " IS COMPLETE"
0
 

Author Comment

by:khufford19
ID: 34207912
@ Brook - Oh, holy crap!  I saw that property in there, but never even THOUGHT to look at it for the number of pages.  Wow!  You've just made my life 1000% better!

Of course, I just realized that I may still have to loop through the original recordset like I was considering earlier, simply because of the way I need to set up the file names of the individual PDF files (I need to use a value from the recordset), but this definitely makes my day.  Thank you SO much!
0
 
LVL 14

Expert Comment

by:Brook Braswell
ID: 34207979
No problems, glad to help
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now