Resolved Trouble creating PDF on iPhone

Discussion in 'iOS Programming' started by waterskier2007, Apr 16, 2014.

  1. waterskier2007, Apr 16, 2014
    Last edited: Apr 17, 2014

    waterskier2007 macrumors 68000


    Jun 19, 2007
    Novi, MI
    Hey guys. I am creating a PDF in my iOS app that the user can then share using the QuickLook Preview View Controller setup. The creation of the PDF works, as I can view the pdf on a computer if I email it to myself, or through any other method to get it on the computer. The problem is that when I first create the PDF and pull it up in the Quick Look View Controller, it shows as a blank grey page. It's almost as if the device doesn't have enough power to render the graphics. The pdf is pretty small (282 kb when I checked it on the computer).

    My question is, is there a way to see if it is not being rendered because of graphical power constraints, or if I am doing something wrong. I will provide code if it is necessary, but I don't really think that it is because I know the PDF is created correctly as I can view it on a computer.
  2. Paulie87, Apr 16, 2014
    Last edited by a moderator: Apr 16, 2014

    Paulie87 macrumors newbie

    Mar 2, 2014
    Try loading it in a uiwebview


        NSString* fileName = @"Invoice.PDF";
        NSArray *arrayPaths =
        NSString *path = [arrayPaths objectAtIndex:0];
        NSString* pdfFileName = [path stringByAppendingPathComponent:fileName];
        UIWebView* webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
        NSURL *url = [NSURL fileURLWithPath:pdfFileName];
        NSURLRequest *request = [NSURLRequest requestWithURL:url];
        [webView setScalesPageToFit:YES];
        [webView loadRequest:request];
        [self.view addSubview:webView];    
  3. waterskier2007, Apr 17, 2014
    Last edited: Apr 17, 2014

    waterskier2007 thread starter macrumors 68000


    Jun 19, 2007
    Novi, MI
    I actually figured out a better way to do it. I was previously using

    [myView.layer renderInContext:pdfContext];
    a bunch of times to correctly lay out the pdf. I instead switched to manually drawing the entire thing, which took more code, but is a MUCH better/quicker/more efficient way to do it and creates a much better looking PDF

    edit: i have changed the thread to resolved

Share This Page