【问题标题】:Display pdf with a capability to place a picture on top of a page显示 pdf 并能够在页面顶部放置图片
【发布时间】:2018-05-31 14:27:05
【问题描述】:

所以我正在尝试为移动应用创建一个功能。 它需要能够在视图中显示 pdf 文件,并允许用户将其签名的相当大的图片放置在所需的位置。

我正在使用 xamarin.forms 并使用以下方法显示 pdf 文件: https://github.com/xamarin/recipes/tree/master/Recipes/xamarin-forms/Controls/display-pdf

现在我需要知道第二部分的最佳方法是什么。 用户放置一张图片,我只需要获取该位置的坐标及其宽度。

到目前为止,我看到了两种可能的方法:

  1. 创建两个相互重叠的视图,第一个用于 pdf,第二个用于签名。允许在第二个中操作图像并从那里获取数据。不知道该怎么做,或者这是否是个好主意。
  2. 让 IOS 以与 Android 相同的方式使用 pdfjs(遇到问题),并在 pdfjs 端实现 fabric.js,然后从那里获取数据。

对于更好的方法有什么建议或想法吗?

谢谢

【问题讨论】:

    标签: ios pdf xamarin.forms mobile-application pdf.js


    【解决方案1】:

    您可以在webView.ScrollView中添加图片和签名,并对其ContentInset进行一些调整。

    1. 先更改 webView.ScrollView.ContentInset

    2. 添加额外的视图。

    3. 使 webView 滚动到正确的位置(原始锚点)。

    完整代码:

    class MyDelegate: UIWebViewDelegate
    {
        public override void LoadingFinished(UIWebView webView)
        {
            webView.ScrollView.ContentInset = new UIEdgeInsets(200, 0, 0, 0);
    
    
            UIView view  = new UIView(frame: new CoreGraphics.CGRect(0, -200, webView.Frame.Width, 200));
            UIImageView image = new UIImageView(frame: new CoreGraphics.CGRect(0, 0, webView.Frame.Width, 100));
            UILabel label = new UILabel(frame: new CoreGraphics.CGRect(0, 100, webView.Frame.Width, 100));
            view.Add(image);
            view.Add(label);
            webView.ScrollView.AddSubview(view);
    
            webView.ScrollView.ContentOffset = new CoreGraphics.CGPoint(0, -200);
        }
    }
    
    public class CustomWebViewRenderer : ViewRenderer<CustomWebView, UIWebView>
    {
        protected override void OnElementChanged (ElementChangedEventArgs<CustomWebView> e)
        {
            base.OnElementChanged (e);
    
            if (Control == null) {
                UIWebView web = new UIWebView();
                web.Delegate = new MyDelegate();
                SetNativeControl(web);
            }
        }
        //xxxxx
    }
    

    【讨论】:

    • 嗨,很抱歉在工作中迷路了。感谢您的回答,最后,我们使用了两个类似于您的解决方案的叠加控制器。将图像添加到 Web 视图,然后对其进行操作。
    猜你喜欢
    • 2011-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-01
    • 1970-01-01
    • 2018-11-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多