Powered By Blogger

Thursday, February 21, 2013

How to capture snapshot of UIWebview in iPhone?


Hi everyone,
Have you ever tried to take a picture of "UIWebView" in any of your applications? Now, you can do it by following below code in your project. You can use scrollview property of UIWebView in iOS 5.0 and later SDK.

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

For example:

#pragma mark --------------------
#pragma mark Take screenshot from Webview
#pragma mark --------------------


UIWebView *receiptWeb;
- (UIImage *)takeScreenshotFromWebview
{
    UIImage *img = nil;
    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"5.0"))
    {
        UIGraphicsBeginImageContextWithOptions(receiptWeb.scrollView.contentSize, receiptWeb.scrollView.opaque, 0.0);
        {
            CGPoint savedContentOffset = receiptWeb.scrollView.contentOffset;
            CGRect savedFrame = receiptWeb.scrollView.frame;
          
            receiptWeb.scrollView.contentOffset = CGPointZero;
            receiptWeb.scrollView.frame = CGRectMake(0, 0, receiptWeb.scrollView.contentSize.width, receiptWeb.scrollView.contentSize.height);
            [receiptWeb.scrollView.layer renderInContext: UIGraphicsGetCurrentContext()];
            img = UIGraphicsGetImageFromCurrentImageContext();
          
            receiptWeb.scrollView.contentOffset = savedContentOffset;
            receiptWeb.scrollView.frame = savedFrame;
        }
        UIGraphicsEndImageContext();
    }
    else
    {
        for (id subview in receiptWeb.subviews)
        {
            if ([subview isKindOfClass:[UIScrollView class]])
            {
                UIScrollView *scrollView = (UIScrollView *)subview;
                UIGraphicsBeginImageContextWithOptions(scrollView.contentSize, scrollView.opaque, 0.0);
                {
                    CGPoint savedContentOffset = scrollView.contentOffset;
                    CGRect savedFrame = scrollView.frame;
                  
                    scrollView.contentOffset = CGPointZero;
                    scrollView.frame = CGRectMake(0, 0, scrollView.contentSize.width, scrollView.contentSize.height);
                    [scrollView.layer renderInContext: UIGraphicsGetCurrentContext()];
                    img = UIGraphicsGetImageFromCurrentImageContext();
                  
                    scrollView.contentOffset = savedContentOffset;
                    scrollView.frame = savedFrame;
                }
                UIGraphicsEndImageContext();
            }
        }
    }
    return img;
}

Regards,
Nilesh Prajapati

Tuesday, February 19, 2013

Best printer sdk for iPhone

Hey everyone,
Now I found one more good things regarding printing in iPhone SDK. I found "STAR MACRONICS" printers having their own SDKs for Both iOS and android devices. By using this SDK, You can easily integrate POS printers and as well as bluetooth, USB printers with your application.

Please take a look to below given link from where you can download SDK and its manual for integration.


Documentation link http://www.starmicronics.com/support/SDKDocumentation.aspx


Regards,
Nilesh Prajapati