0

I am working on building an app that will generate PDFs. I can generate the PDF just fine, but it is a one-click action that builds and saves the PDF. What I would like to do is change it to showing a preview of the PDF and then giving the option to edit things, or save it to the Documents folder. How can I go about doing this? Here is what I have that saves it.

- (IBAction)generatePdfButtonPressed:(id)sender
{
    pageSize = CGSizeMake(792, 612);
    NSString *fileName = @"Demo.pdf";
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *pdfFileName = [documentsDirectory stringByAppendingPathComponent:fileName];

    [self generatePdfWithFilePath:pdfFileName];
}
- (void) generatePdfWithFilePath: (NSString *)thefilePath
{
    UIGraphicsBeginPDFContextToFile(thefilePath, CGRectZero, nil);


    BOOL done = NO;
    do
    {

        UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, pageSize.width, pageSize.height), nil);


         [self drawImage];

        [self drawText];
        [self drawText2];
        [self drawText3];
        [self drawText4];


        done = YES;
    }
    while (!done);

    // Close the PDF context and write the contents out.
    UIGraphicsEndPDFContext();
}
Sebastian
  • 7,670
  • 5
  • 38
  • 50
user717452
  • 33
  • 14
  • 73
  • 149

1 Answers1

0

Create a view with a UIWebview. Then you can simply load the PDF document that you have saved into the webview

Stephen
  • 1,427
  • 1
  • 17
  • 42
  • My issue is that I'm needing to preview the PDF before saving it. Your suggestion would save the PDF, and then display it. I'm wanting a preview option so that no document is saved first. – user717452 Apr 15 '13 at 02:55
  • is there any particular reason you are against saving it? If the user cancels or doesn't want it anymore you can simply delete the document – Stephen Apr 15 '13 at 02:56
  • 2
    instead of loading the document in web view, just load the data in the uiwebview, that will become your preview – Nikita P Apr 15 '13 at 05:20