?
Solved

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

Posted on 2010-11-24
6
Medium Priority
?
940 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month8 days, 10 hours left to enroll

765 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