Solved

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

Posted on 2010-11-24
6
890 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
Comment Utility
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
Comment Utility
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
Comment Utility
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 14

Expert Comment

by:Brook Braswell
Comment Utility
                              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
Comment Utility
@ 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
Comment Utility
No problems, glad to help
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

744 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

15 Experts available now in Live!

Get 1:1 Help Now