我嘗試找到在 xamarin.forms 上顯示本地 pdf 文件的方法。我找到了一個實現 webview 及其渲染的自定義實現的解決方案:pdf 閱讀器主要代碼是:public class CustomWebView : WebView{ public static readonly BindableProperty UriProperty = BindableProperty.Create<CustomWebView, string>(p => p.Uri, default(string)); public string Uri { get { return (string)GetValue(UriProperty); } set { SetValue(UriProperty, value); } }}使成為:[assembly: ExportRenderer (typeof(CustomWebView), typeof(CustomWebViewRenderer))]namespace DisplayPDF.iOS{ public class CustomWebViewRenderer : ViewRenderer<CustomWebView, UIWebView> { protected override void OnElementChanged (ElementChangedEventArgs<CustomWebView> e) { base.OnElementChanged (e); if (Control == null) { SetNativeControl (new UIWebView ()); } if (e.OldElement != null) { // Cleanup } if (e.NewElement != null) { var customWebView = Element as CustomWebView; string fileName = Path.Combine (NSBundle.MainBundle.BundlePath, string.Format ("Content/{0}", WebUtility.UrlEncode (customWebView.Uri))); Control.LoadRequest (new NSUrlRequest (new NSUrl (fileName, false))); Control.ScalesPageToFit = true; } } }}還有我的頁面:public class WebViewPageCS : ContentPage { public WebViewPageCS () { webView = new CustomWebView { Uri = "ScalaReference.pdf", HorizontalOptions = LayoutOptions.FillAndExpand, VerticalOptions = LayoutOptions.FillAndExpand }; }但是現在我找不到像這篇文章中描述的那樣向這個 pdf 文件添加錨點的方法:anchor to pdf我還嘗試將此代碼用于評估腳本:private async void Scroll_Clicked(object sender, EventArgs e){ webView.Eval($"window.scrollTo(0, {x});");}它適用于默認 webview,但不適用于自定義 webview。也許有人知道通過 xamarin.forms 將錨點滾動/設置為 pdf 并鏈接到該錨點的任何其他方法?謝謝你。
- 1 回答
- 0 關注
- 142 瀏覽
添加回答
舉報
0/150
提交
取消