Create a 1-page PDF screen for iPad. How?

I asked this question in several other forums and got a null answer, so I hope someone can help point me in the right direction. I have a pretty simple one screen app for my job. It's basically just a recreation of a 1-page paper report with a company logo, some labels, a few text boxes, and a scroll text box for the report.

I need to be able to fill out a report and then click a button to save it graphically so that I can fax, print or email it later. Currently I just programmatically grab the screen capture and save it to my photo library (default for screen capture). Then I can just email it. This works fine, but is hacks at best.

I read the new iPad 3.2 tutorial for PDF creation (apparently it was much easier than it used to be), but I can't get it to work and I've spent countless hours on it. I hope someone has an answer for me.

Alternatively, if anyone knows how I can redirect where the screen capture is stored (default in photo album), maybe I can get this function to work. If I could redirect the screen capture to be stored in the application documents folder, then I can use MFMailCompose to attach to the email.

Finally, on the side of the note, does anyone know of a good way to capture a digital signature with a touch. For example, I would like my users to be able to simply sign their name with a tap at the bottom of the document before converting to PDF or taking a screen capture.

Thanks in advance for your help. -Ray

+2


source to share


1 answer


I am using the following snippet. it works great with creating one page PDF . It takes whatever kind of content you have and write it as a PDF file and is stored in the document directory.

for some function



{
 ....
    // here container view is my content to be converted to PDF file
    // filepath is the path to where it should be write in our documents directory
    CGContextRef pdfContext = [self createPDFContext:containerView.bounds path:(CFStringRef)filePath];  
    NSLog(@"PDF Context created");
    CGContextBeginPage (pdfContext,nil); // 6

    //turn PDF upsidedown   
    CGAffineTransform transform = CGAffineTransformIdentity;    
    transform = CGAffineTransformMakeTranslation(0, containerView.bounds.size.height);  
    transform = CGAffineTransformScale(transform, 1.0, -1.0);   
    CGContextConcatCTM(pdfContext, transform);  

    //Draw view into PDF
    [containerView.layer renderInContext:pdfContext];   
    CGContextEndPage (pdfContext);// 8  
    CGContextRelease (pdfContext);

 ....
}

- (CGContextRef) createPDFContext:(CGRect)inMediaBox path:(CFStringRef) path    
{   
    CGContextRef myOutContext = NULL;   
    CFURLRef url;   
    url = CFURLCreateWithFileSystemPath (NULL, // 1                                      
                                         path,                                       
                                         kCFURLPOSIXPathStyle,                                       
                                         false);

    if (url != NULL) {      
        myOutContext = CGPDFContextCreateWithURL (url,// 2                                                
                                                  &inMediaBox,                                                
                                                  NULL);        
        CFRelease(url);// 3     
    }   
    return myOutContext;// 4    
}

      

0


source







All Articles