开发者

Creating 1 page PDF of iPad Screen view - How?

开发者 https://www.devze.com 2022-12-26 07:05 出处:网络
I\'ve asked this question on a couple other forums and have had zero response, so I\'m hoping someone here can help point me in the right direction. I have a pretty simple one screen application for m

I've asked this question on a couple other forums and have had zero response, so I'm hoping someone here can help point me in the right direction. I have a pretty simple one screen application for my work. It's basically just a recreation of a 1 page paper report that has 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 th开发者_高级运维e report then click a button to save it in a graphical form so I can fax, print or email it later. Currently, I'm just programmatically taking a screen capture and saving it to the photo's library (default for screen capture). Then I can just email it from photo's. This works ok, but is kind of hacky, at best.

I've read through the new iPad 3.2 guide for creating PDF's (apparently it's supposed to be much easier than before) but I can not get it to work and I've spent countless hours on it now. I'm hoping someone has the answer for me.

Alternatively, if anyone knows how I can redirect where the screen capture is stored (default is in the photo album) then maybe I can make that function work. If I could redirect the screen capture to store in my applications document folder, then I can use MFMailCompose to attach it to an email.

Lastly, on a side note, does anyone know of a good way to capture a digital signature via touch. For instance, I'd love to have my users be able to just sign their name via touch at the bottom of the document before I convert to PDF or take a screen capture.

Thanks in advance for your help. -Ray


I am using the following snippet. it works fine with single page PDF generation. It uses any View where you have content and capture it as a PDF file and stores into the document directory.

on 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

精彩评论

暂无评论...
验证码 换一张
取 消