Operating system requirements: iOS 5.0 or later.
Mobile device: iPad.
This example describes some methods of working with PDF page view. After starting the example the following operations are executed:
Current regular report document URL is retrieved.
A PDF page object is created.
PDF document page is set in the PDF page object.
A PDF page view is created.
PDF document page, page index, and PDF page object are set for the created view.
PDF document page and PDF page size are retrieved from the created view.
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 object 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 sheet viewer if([controller isMemberOfClass:[MAProceduralReportDataViewController class]]) { // Get sheet viewer view MAProceduralReportDataViewController *dataViewController =(MAProceduralReportDataViewController *)controller; // Get regular report viewer view MAProceduralReportDataViewControllerBase *reportDataViewControllerBase = (MAProceduralReportDataViewControllerBase *)dataViewController; // Get URL of regular report current document NSURL *url = [dataViewController urlForCurrentDocument]; CFURLRef urlForCurrentDocument = (CFURLRef)url; // Create a PDF document by means of obtained URL CGPDFDocumentRef pdfDocument = CGPDFDocumentCreateWithURL(urlForCurrentDocument); // Get PDF document page with the 1 index (Numbering in PDF documents starts from 1) CGPDFPageRef pdfPage = CGPDFDocumentGetPage(pdfDocument, 2); // Create a PDF page object PdfPage *page = [[PdfPage alloc] init]; // Set PDF document page in PDF page object [page setPage:pdfPage]; // Get view for selecting PDF document pages PdfPageSelector *pageSelector = [reportDataViewControllerBase pageSelector]; // Get indent of page with the 1 index (array numbering starts from 0) float offset = [[[pageSelector thumbnailsCoordinates] objectAtIndex:1] floatValue]; // Set page indent in PDF page object [page setOffset:offset]; // Create a PDF page view PdfPageView *pageView = [[PdfPageView alloc] init]; // Set PDF document page for display [pageView setPdfPageRef:pdfPage]; // Set PDF page object for display [pageView setPdfPage:page]; // Set page index for display [pageView setPageIndex: 1]; // Display page indent from document start in the development environment console PdfPage *page2 = [pageView pdfPage]; NSLog(@"Page indent from document start: %f", [page2 offset]); // Display page index in the development environment console NSLog(@"Page index: %d", [pageView pageIndex]); // Display page size in the development environment console CGSize size = [pageView pageSize]; NSLog(@"Page width: %f", size.width); NSLog(@"Page height: %f", size.height); // Get PDF document page from display CGPDFPageRef ref = [pageView pdfPageRef]; // Get PDF document containing PDF page CGPDFDocumentRef document = CGPDFPageGetDocument(ref); // Display number of document pages in the development environment console int numberOfPages = CGPDFDocumentGetNumberOfPages(document); NSLog(@"Number of document pages: %d", numberOfPages); // Display PDF page view on mobile device screen [self.view addSubview: pageView]; } }
After executing the example the mobile device screen displays PDF page view:
The development environment console also displays information on displayed PDF page:
Page indent from document start: 117.136612
Page index: 1
Page width: 594.510254
Page height: 841.152771
Number of document pages: 6
See also: