2011-12-02 2 views
0

WebView를 가져 와서 PDF로 변환하려고합니다. 뷰를 이미지로 변환하는 코드가 있지만 PDF가 필요합니다.WebView를 PDF로 변환

public void ConvertToPDF(UIWebView webView) 
{ 
    RectangleF canvasRect = view.Bounds; 
    CGPDFInfo info = new CGPDFInfo(); 
    info.AllowsPrinting = true; 
    UIGraphics.BeginPDFContext (Path.Combine(Environment.GetFolderPath (Environment.SpecialFolder.Personal),"MyDocument.PDF"), canvasRect, info); 
    UIGraphics.BeginPDFPage(); 
    CGContext gctx = UIGraphics.GetCurrentContext(); 

    view.Layer.RenderInContext (ctx); 

    UIGraphics.EndPDFContent(); 
} 

위의 코드는 모두 공란 pdf입니다.

감사 릭

+0

당신은 저를 위해 이미지에 웹뷰를 변환하는 코드를 게시하시기 바랍니다 수 있습니다 작동 안됨 – Ravi

답변

0

CGPDFPageRef 페이지 = CGPDFDocumentGetPage (pdfDocument, 1);

UIImage *pageImage = [PDFPageConverter convertPDFPageToImage:page withResolution:144]; 
NSString *pngPath = [NSHomeDirectory() stringByAppendingPathComponent:destinationPath]; 
[UIImagePNGRepresentation(pageImage) writeToFile:pngPath atomically:YES]; 

거즈가 바로 아래 링크에서 또는 다운로드 예를 작동 할 수 CGPDFDocument 객체와 페이지 번호를 통과 할 것입니다이 코드는 http://ipdfdev.com/2011/04/22/convert-an-image-to-pdf-on-the-iphone-and-ipad/