0

I would like to use CGPDF API to show and manipulate the PDF on IPAD, but firstly, I'm trying to just show PDF on my view from the easy way (without screen adjusts). I don't know why PDF doesn't appear im my application, maybe i'm doing sth wrong. I'm using NSLOG to count pages, it does works, but PDF doesn't appear, just appear white background on my emulator screen.

Here is my code:

//
**//  ViewController.h**
//  MeuCGPDF
//
//  Created by admin on 01/11/13.
//  Copyright (c) 2013 admin. All right reserved.
//

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@end


----------------------------------------------------------

//
**//  ViewController.m**
//  MeuCGPDF
//
//  Created by admin on 01/11/13.
//  Copyright (c) 2013 admin. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    NSString *pathToPdfDoc = [[NSBundle mainBundle] pathForResource:@"livro" ofType:@"pdf"];
    NSURL *pdfUrl = [NSURL fileURLWithPath:pathToPdfDoc];
    CGPDFDocumentRef document = CGPDFDocumentCreateWithURL((CFURLRef)pdfUrl);
    size_t pageCount = CGPDFDocumentGetNumberOfPages(document);

    CGPDFPageRef page = CGPDFDocumentGetPage(document, 1);

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextDrawPDFPage(context, page);

    NSLog(@"Paginas: %zu", pageCount);
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

----------------------------------------------------------
rmaddy
  • 314,917
  • 42
  • 532
  • 579
jbernardo
  • 161
  • 1
  • 4
  • 14
  • IF YOU WANT TO JUST DISPLAY PDF THEN ONLY YOU CAN DISPLAY IT IN UIWEBVIEW USING LOADREQUEST METHOD. THERE IS NO ANY THIRD PARTY API REQUIRED. USE IT IF YOU WANT TO CREATE PDF. – Pradhyuman sinh Nov 01 '13 at 12:57
  • @PradhyumanChavda Fix your caps lock key – rmaddy Nov 01 '13 at 14:11
  • Well, I did that with UIWEBVIEW, but I need to manipulate my PDF, and LOADREQUEST, if i'm not wrong, just show PDF on my screen. Therefore, I've to choice CGPDF, because I have more powers with it. – jbernardo Nov 01 '13 at 17:33

1 Answers1

0

If you want to just display a PDF in web view then :

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.pdfWebView.delegate=self;
    [self displayPdfinWebView];
}

-(void)displayPdfinWebView {
    NSString *path = [[NSBundle mainBundle] pathForResource:@"YourPDFname" ofType:@"pdf"];
    NSURL *targetURL = [NSURL fileURLWithPath:path];
    NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
    [self.pdfWebView loadRequest:request];
}

If you want to have additional features like zoom with double tap or pinch, I wont recommend using WebView due to lack in performance n quality. Theres Apple code for ZoomingPdfViewer which adds a TileLayer with levelsOfDetail n levelsOfDetailBias which is decent for normal pdf sizes.

Hope that helps.

Vacca
  • 1,219
  • 16
  • 26