xamarin.android - Draw PDF out of WebView Xamarin Android -
i have string contains html object , use following code draw pdf of resulted webpage in xamarin android.
android.webkit.webview webpage = new android.webkit.webview(application.context); int width = 2102; int height = 2973; webpage.layout(0, 0, width, height); webpage.loaddata(htmlstring, "text/html", "utf-8"); webpage.setwebviewclient(new webviewcallback(pdffilepath));
webviewcallback class inherits webviewclient , has following method gets called webview ready:
public override void onpagefinished(android.webkit.webview mywebview, string url) { pdfdocument document = new pdfdocument(); pdfdocument.page page = document.startpage(new pdfdocument.pageinfo.builder(2120, 3000, 1).create()); mywebview.draw(page.canvas); document.finishpage(page); stream filestream = new memorystream(); filestream fos = null; try { fos = new filestream(filenamewithpath, filemode.openorcreate); document.writeto(filestream); fos.write(((memorystream)filestream).toarray(), 0, (int)filestream.length); fos.flush(); fos.close(); } catch(exception x) { //do } }
problem though webview seems load blank pdf. ideas?
could suggest simliar way using xamarin.forms.webview instead of android.webkit.webview?
Comments
Post a Comment