我正在尝试将 PDFTron 用于 Xamarin Android。我想渲染和绘制我的自定义注释,而不使用他们的注释系统。根据他们在https://www.pdftron.com/documentation/xamarin/guides/ui-customization/custom-view/android/中的文档,您可以添加一个不起作用的 CustomRelativeLayout。它基本上不会在 PDF 顶部呈现任何内容
我在这里http://s000.tinyupload.com/index.php?file_id=14574507524295393508托管了整个解决方案,因此很容易测试,看看是否有人能看到问题所在。
谢谢!
更新
尝试了 Shirley G 的建议。修改了要添加到的 pdf_custom_layout:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="50dp"
android:layout_height="50dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Custom Layout Text View"
android:textSize="24dp"
android:elevation="2dp"/>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_red_dark" />
</LinearLayout>
和代码:
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
public class MainActivity : AppCompatActivity
{
private PDFViewCtrl _pdfControl;
private PDFDoc _doc;
protected override void OnCreate(Bundle savedInstanceState)
{
PDFNet.Initialize(this, Resource.Raw.pdfnet, "Insert commercial license key here after purchase");
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.activity_main);
_pdfControl = FindViewById<PDFViewCtrl>(Resource.Id.pdfControl);
var assets = this.Assets;
using var sr = new StreamReader(assets.Open("dummy.pdf"));
_doc = new PDFDoc(sr.BaseStream);
_pdfControl.DocumentLoad += _pdfControl_DocumentLoad;
_pdfControl.SetDoc(_doc);
}
private void _pdfControl_DocumentLoad(object sender, System.EventArgs e)
{
var overlay = new CustomRelativeLayout(BaseContext);
var color = new Android.Graphics.Color(BaseContext.GetColor(Resource.Color.red));
overlay.SetBackgroundColor(color);
overlay.SetZoomWithParent(true);
LayoutInflater.Inflate(Resource.Layout.pdf_custom_layout, overlay);
_pdfControl.AddView(overlay);
}
但是什么也没发生,仍然没有显示覆盖。
更新 2
我添加了修复程序并开始工作,但是,当我添加此代码时:
var overlay = new CustomRelativeLayout(BaseContext, _pdfControl, 50, 50, 1);
overlay.SetBackgroundColor(BaseContext.Resources.GetColor(Resource.Color.orange));
overlay.SetZoomWithParent(true);
_pdfControl.AddView(overlay);
overlay.LayoutParameters.Width = 300;
overlay.LayoutParameters.Height = 300;
_pdfControl.Invalidate();
overlay.RequestLayout();
我在页面位置 x=50 和 y50 看到一个 50x50 的小矩形。我指定覆盖的宽度为 300,但它没有显示出来。
如果我添加它,则根本不会显示任何内容,即使在 x=0、y =0 时叠加层应该是 300x300。
var overlay = new CustomRelativeLayout(BaseContext, _pdfControl, 0, 0, 1);