Getting Information on Regular Report Sheet

Operating system requirements: iOS 5.0 or later.

Mobile device: iPad.

Description

This example describes getting of information on regular report sheet. After starting the example the following operations are executed:

Source Code

Executing the example requires to place the following code in the body of the executeExample method of the ViewController class (see the Displaying of Regular Report section):

// Delete all window subviews
NSArray *reportSubviews = [self.view subviews];
for(UIView *subView in reportSubviews)
{
    [subView removeFromSuperview];
}
// Get regular report view
MAProceduralReportViewController *proceduralReportController = (MAProceduralReportViewController *)m_controller;
// Get array of regular report views
NSArray *dataViewControllers = [proceduralReportController dataViewControllers];
// Parse regular report views in cycle
for( UIViewController *controller in dataViewControllers)
{
    // Check if the current view is a regular report viewer view
    if([controller isMemberOfClass:[MAProceduralReportDataViewController class]])
    {
        // Get sheet viewer view
        MAProceduralReportDataViewController *dataViewController =(MAProceduralReportDataViewController *)controller;
        // Get regular report viewer view
        MAProceduralReportDataViewControllerBase *reportDataViewControllerBase = (MAProceduralReportDataViewControllerBase *)dataViewController;
        // Get regular report data source from sheet viewer view
        id<MAProceduralReportViewControllerDelegate> dataSource = [dataViewController dataSource];
        // Get number of sheets
        int worksheetCount = [dataSource worksheetCount];
        if(worksheetCount > 0)
        {
            // Check if selected sheet is visible
            if([dataSource isWorksheetVisibleAtIndex:worksheetCount - 1] == YES)
            {
                // Display regular report sheet name and key in the development environment console
                NSString *worksheetName = [dataSource worksheetNameAtIndex:worksheetCount - 1];
                int worksheetKey = [dataSource worksheetKeyAtIndex:worksheetCount - 1];
                NSLog(@"Regular report sheet: %@, key: %d",worksheetName, worksheetKey);
                // Check if selected sheet is PDF document
                if([[dataSource worksheetExtAtIndex:worksheetCount - 1] isEqualToString:@"pdf"] == YES)
                {
                    // Get regular report sheet path
                    NSString *worksheetFullpath = [dataSource worksheetFullpathAtIndex:worksheetCount - 1];
                    // Get regular report sheet URL
                    CFURLRef url = (CFURLRef)[NSURL fileURLWithPath:worksheetFullpath];
                    // Open PDF document
                    CGPDFDocumentRef pdfDocument = CGPDFDocumentCreateWithURL(url);
                    // Get first page (PDF document pages are numbered from the first page)
                    CGPDFPageRef pdfPage = CGPDFDocumentGetPage(pdfDocument, 1);
                    // Get page object
                    PdfPage *page = [[PdfPage alloc] initWithPage:pdfPage];
                    // Display page information in the development environment console
                    float width = [page width];
                    float heght = [page height];
                    float scale = [page scale];
                    CGFloat offset = [page offset];
                    NSLog(@"Page width: %f, page height: %f", width, heght);
                    NSLog(@"Page scale factor: %f, page indent from document start: %f", scale, offset);
                }
            }
        }
        // Get current page index
        int currentPage = [dataViewController currentPage];
        // Check if the next page exists
        if(currentPage + 1 < [dataViewController pagesCount])
        {
            // Go to the next page
            [dataViewController jumpToPage: currentPage + 1];
        }
        // get PNG data fro screenshot
        NSData *data = [reportDataViewControllerBase workspacePNGData];
        // Create an image based on obtained data
        UIImage *image = [[UIImage alloc] initWithData:data];
        // Display obtained image on mobile device screen
        UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
        [self.view addSubview:imageView];
    }
}

 After executing the example the development environment console displays name and key of the selected regular report sheet, parameters of the PDF page created by means of information on the selected sheet:

Regular report sheet: Map, key: 10

Page width: 841.124390, page height:  594.538574

Page scale factor:  1.000000, page indent from document start:  0.000000

 

The mobile device screen also displays the screenshot of the regular report page, to which transition is executed:

See also:

Examples of Component Use