Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

waterskier2007

macrumors 68000
Original poster
Jun 19, 2007
1,871
228
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.
 
Last edited:

Paulie87

macrumors newbie
Mar 2, 2014
24
0
Try loading it in a uiwebview

----------

Code:
-(void)showPDFFile
{
    NSString* fileName = @"Invoice.PDF";
 
    NSArray *arrayPaths =
    NSSearchPathForDirectoriesInDomains(
                                        NSDocumentDirectory,
                                        NSUserDomainMask,
                                        YES);
    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];    
}
 
Last edited by a moderator:

waterskier2007

macrumors 68000
Original poster
Jun 19, 2007
1,871
228
Novi, MI
I actually figured out a better way to do it. I was previously using

Code:
[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
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.