开发者

Problems accessing FieldObject for page count

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开发者_C百科 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.


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


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)


I know this is an old question, but I have a solution about printing to different trays. Its all about defining the printers papersource, see the example code below...

PageRange range = pageRange;
var tray = printerToUse.PrinterTrays.FirstOrDefault(t => t.PaperTypeId == range.PaperTypeId);
var printerSettings = new PrinterSettings
                    {
                        FromPage = pageRange.StartPage,
                        ToPage = pageRange.EndPage ?? 0,
                        PrinterName = printerToUse.PrinterName,
                        Copies = copies,
                    };
PaperSource paperSource = printerSettings.PaperSources
                    .OfType<PaperSource>()
                    .FirstOrDefault(
                        ps => ps.SourceName.Trim().Equals(tray.Name, StringComparison.InvariantCultureIgnoreCase));
                var pageSettings = new PageSettings(printerSettings)
                    {
                        PaperSource = paperSource,
                    };
_internalDocument.PrintToPrinter(printerSettings, pageSettings, false);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜