views:

572

answers:

2

Hi,

We're using Crystal Reports.NET that was bundled with VS2005. We have a confirmation booking form letter report that we want to batch print. Generally this prints one page per person on letterhead paper, however occasionally if they've booked lots of courses the letter rolls over to two pages. The second page should not be printed to letterhead paper.

Basically, because it's a rare occurance I was just going to print the lot and pause if a particular letter went over 1 page. I.e. Load the report, grab the page count, hollah at the user if it's more than one page otherwise carry on regardless.

I have dropped a TotalPageCount on the footer of my report (Which I would supress if it worked!) and then try and read it in my application.

Once I've loaded the document I am trying to call

report.ReportDefinition.ReportObjects("TotalPageCount1")

Which is of type CrystalDecisions.CrystalReports.Engine.FieldObject

I cannot seem to get the value out of this for love nor money (nor any amount of cursing and swearing!)

I can read any items of type TextObject, but if I append the TotalPageCount to a text field, it shows correctly in the report but then returns "Page count: TotalPageCount" rather than "Page count: 1" for example.

Soo, short of going out of my mind, does anyone have any suggestions? Either a way to read the value or a way round it. The printer doesn't have multiple trays, though even if we got one, I'm not sure how to convince crystal to print different pages to different trays.

Best regards,

Stuart

P.S. - is it a sign that the "crystal-reports" tag has a count of 666? :O(

A: 

Why not embed the total-page count field into a formula field, then get the value of the formula field?

Try ReportDocument.FormatEngine.GetLastPageNumber(New CrystalDecisions.Shared.ReportPageRequestContext)

Craig
thanks for the response, but I tried that, a forumla field doesn't return a value either. I only seem to be able to retrieve the value of a TextObject field type, and if I append the TotalPageCount to the text field by dragging it in, it just prints the name, not the value.
Stuart A
Also, and I double checked just to be 100%! If I create a formula field and append that to a text field such as "Page count: {@PageCount}" then it jsut retrieves "Page count: {@PageCount}" and not "Page count: 2" etc ;O(
Stuart A
A: 

I just spent an age searching out this answer. Think I've managed to get it working as follows.. (VC2008, C#.net Windows Forms viewer etc)

using CrystalDecisions.Shared;

int iPageCount = report1.FormatEngine.GetLastPageNumber(new ReportPageRequestContext());

  • not sure why but my autocomplete didn't even register the FormatEngine. But true enough it worked.

Hope it helps!

James Kent

James Kent