コード例 #1
0
        public string GetAttachmentDir(BaseInboxMessage req)
        {
            string cacheDir = fileSystem.GetFilesDir();
            string attPath  = fileSystem.JoinPaths(cacheDir, "reqs", req.Id.ToString());

            fileSystem.CreateFolder(attPath);
            return(attPath);
        }
コード例 #2
0
        private void ShowPDF()
        {
            string pdfFolder = GetPDFDir(this.SignatureRequest);
            string fileName  = fileSystem.JoinPaths(pdfFolder, "document.pdf");

            fileSystem.CreateFolder(pdfFolder);

            using (var stream = fileSystem.GetFileStream(fileName))
            {
                stream.Write(Document.PdfContent, 0, Document.PdfContent.Length);
                stream.Flush();
            }

            HtmlWebViewSource html = new HtmlWebViewSource();

            if (Device.OS != TargetPlatform.iOS)
            {
                //Existe um bug no WebView do iOS: https://developer.xamarin.com/guides/xamarin-forms/working-with/webview/
                html.BaseUrl = DependencyService.Get <IBaseUrl>().Get();
            }

            string pageSource = String.Format(
                @"<html>
	                        <head>
		                        <script type = 'text/javascript'>
			                        var url = 'file://{0}';
		                        </script>
		                        <script type='text/javascript' src='compatibility.js'></script>
	                        </head>
	                        <body>
		                        <div id='pages'>
	                            </div>

	                            <script type='text/javascript' src='../build/pdf.js'></script>
	                            <script type='text/javascript' src='customview.js'></script>
	                        </body>
	                        </html>"    , fileName);

            try
            {
                if (Device.OS != TargetPlatform.iOS)
                {
                    html.Html         = pageSource;
                    pdfWebView.Source = html;
                }
                else
                {
                    //iOS requires this action on the main UI thread
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        html.Html         = pageSource;
                        pdfWebView.Source = html;
                    });
                }

                //url.Url = DependencyService.Get<IBaseUrl>().Get() + "index.html"; //?file=" + WebUtility.UrlEncode(fileName.Result);
                PdfShareViewModel.FileName = fileName;
                PdfShareViewModel.MimeType = "application/pdf";
                pdfLoaded = true;
            }
            catch (Exception e)
            {
                UserDialogs.Instance.Alert(e.Message, AppResources.APP_TITLE, AppResources.OK);
            }
        }