2013-03-14 50 views
0

我試圖從UIWebView生成PDF報告。使用Graphics Contexts我可以得到屏幕框架的圖像並以PDF格式繪製。在CURENT方法IOS - 從iphone中的UIwebview生成PDF

的問題是, 圖像是模糊的(質量差) 因此該報告的PDF無法讀取。

如何獲得高質量的屏幕畫面圖像?或者有沒有其他更好的解決方案來解決我的問題?

P.S.報告包含多種背景顏色和圖像,我認爲很難直接在PDF中繪製它們。

回答

0
+ (UIImage *) imageWithView:(UIView *)view 
{ 
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0); 
    [view.layer renderInContext:UIGraphicsGetCurrentContext()]; 

    UIImage * img = UIGraphicsGetImageFromCurrentImageContext(); 

    UIGraphicsEndImageContext(); 

    return img; 
} 
+0

感謝您的回答。目前的圖像是好的,但PDF是blured – 2013-03-14 13:02:58

+0

審查@wesley答案 – Rushabh 2013-03-14 13:05:29

0
NSMutableData *pdfData = [NSMutableData data]; 
UIGraphicsBeginPDFContextToData(pdfData, webview.bounds, nil); 
UIGraphicsBeginPDFPage(); 
CGContextRef pdfContext = UIGraphicsGetCurrentContext(); 
[webview.layer renderInContext:pdfContext]; 
UIGraphicsEndPDFContext(); 

你試過這樣嗎?

+0

謝謝4 da答覆..我的網絡視圖的滾動高度是1500 ..所以我必須捕捉部分屏幕部分和加入。 – 2013-03-14 10:01:35

+0

然後把你想要的x,y座標作爲框架作爲單獨的uiview,然後將其渲染爲pdf – wesley 2013-03-14 10:12:43