I am trying to open a pdf file on a Xamarin project using webview and i was able to do it using the following :
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); RequestWindowFeature(WindowFeatures.NoTitle); SetContentView(Resource.Layout.ViewReport); var mywebview = FindViewById<WebView>(Resource.Id.webView1); var myurl= "http://docs.google.com/gview?embedded=true&url=http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf"; mywebview.Settings.AllowFileAccess = true; mywebview.Settings.JavaScriptEnabled = true; mywebview.Settings.BuiltInZoomControls = true; mywebview.LoadUrl(myurl); mywebview.SetWebViewClient(new PodWebViewClient()); } My problem is that the PDF file that i am trying open is created via Itextsharp from my MVC project:
public ActionResult Print() { var document = new iTextSharp.text.Document(PageSize.A4, 50, 50, 25, 25); var output = new MemoryStream(); var writer = PdfWriter.GetInstance(document, output); document.Open(); string contents = System.IO.File.ReadAllText(Server.MapPath("~/Content/HTMTemplate/pdf_template.htm"), Encoding.Unicode); //==================== // do something here... //==================== FontFactory.Register(Server.MapPath("~/fonts/ARIALUNI.TTF")); StyleSheet ST = new StyleSheet(); ST.LoadTagStyle(HtmlTags.BODY, HtmlTags.FACE, "Arial Unicode MS"); ST.LoadTagStyle(HtmlTags.BODY, HtmlTags.ENCODING, BaseFont.IDENTITY_H); var parsedHtmlElements = HTMLWorker.ParseToList(new StringReader(contents), ST); foreach (var htmlElement in parsedHtmlElements) document.Add(htmlElement as IElement); document.Close(); var cd = new System.Net.Mime.ContentDisposition { FileName = "samplepdf.pdf", Inline = true }; Response.AppendHeader("Content-Disposition", cd.ToString());//open in browser return File(output.ToArray(), "application/pdf"); } but when i did the following:
var myurl= "http://docs.google.com/gview?embedded=true&url=http://www.sample.com/doc/print"; i was shown a text file with html tags and not my pdf file.
How should i fix this? I think my problem lies in my pdf file but I don't know which is it as I was able to open the pdf in my browser.. Hope you can help me. Thanks.