Solved

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

Posted on 2010-11-24
6
898 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

839 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