実際にはXamarin.MacのPDFKitでマークアップアノテーションを追加しようとしています。そのため、OS Xではを強調しています注釈としてPDFファイル内の選択されたテキストを永久的に保存し、後でそのファイルを開くときにそれを取得するために保存します。Xamarin.Mac - PDFファイルで選択したテキストを強調表示する方法
事は、私は現在の選択を取得し、変数にそれを保存することができ、次のとおりです。
PdfSelection currentSelection = m_aPdfView.CurrentSelection;
そして、私はオブジェクトPdfAnnotationMarkup作成することができます、
//Create the markup annotation
var annot = new PdfAnnotationMarkup();
//add characteristics to the annotation
annot.Contents = currentSelectionText;
annot.MarkupType = PdfMarkupType.Highlight;
annot.Color = NSColor.Yellow;
annot.ShouldDisplay = true;
をしかし、私は見つけることができません私は多くの異なる文書をチェックしましたが、それらの2つをリンクする方法はありました。 currentSelectionの位置を指定する方法や、その方向に進むヒントがありません。
これを可能にする方法は誰にも分かりますか?
PS:PDFAnnotationのサブクラスはApple Developer Websiteで廃止されましたが、Xamarin Websiteではなく、両方が完全に異なるかどうかを知る方法はありますか?あなたの助けを事前に
おかげ
編集:ここに私が持って、完璧に動作するコードです。 svnのお返事ありがとうございます
//Get the current selection on the PDF file opened in the PdfView
PdfSelection currentSelection = m_aPdfView.CurrentSelection;
//Check if there is an actual selection right now
if (currentSelection != null)
{
currentSelection.GetBoundsForPage(currentSelection.Pages[0]);
//Create the markup annotation
var annot = new PdfAnnotationMarkup();
//add characteristics to the annotation
annot.Contents = "Test";
annot.MarkupType = PdfMarkupType.Highlight;
annot.Color = NSColor.Yellow;
annot.ShouldDisplay = true;
annot.ShouldPrint = true;
annot.UserName = "MyName";
//getting the current page
PdfPage currentPage = currentSelection.Pages[0];
//getting the bounds from the current selection and adding it to the annotation
var locationRect = currentSelection.GetBoundsForPage(currentPage);
getValuLabel.StringValue = locationRect.ToString();
//converting the CGRect object into CGPoints
CoreGraphics.CGPoint upperLeft = locationRect.Location;
CoreGraphics.CGPoint lowerLeft = new CoreGraphics.CGPoint(locationRect.X, (locationRect.Y + locationRect.Height));
CoreGraphics.CGPoint upperRight = new CoreGraphics.CGPoint((locationRect.X + locationRect.Width), locationRect.Y);
CoreGraphics.CGPoint lowerRight = new CoreGraphics.CGPoint((locationRect.X + locationRect.Width), (locationRect.Y + locationRect.Height));
//adding the CGPoints to a NSMutableArray
NSMutableArray pointsArray = new NSMutableArray();
pointsArray.Add(NSValue.FromCGPoint(lowerLeft));
pointsArray.Add(NSValue.FromCGPoint(lowerRight));
pointsArray.Add(NSValue.FromCGPoint(upperLeft));
pointsArray.Add(NSValue.FromCGPoint(upperRight));
//setting the quadrilateralPoints
annot.WeakQuadrilateralPoints = pointsArray;
//add the annotation to the PDF file current page
currentPage.AddAnnotation(annot);
//Tell the PdfView to update the display
m_aPdfView.NeedsDisplay = true;
ご返信ありがとうございます。 あなたのソリューションでは、実際にcurrentSelectionの境界を取得できますが、注釈はPDFに表示されません。私はlocationRectを追加しましたが。 しかし、このソリューションのおかげで、私はどのように私はそれを逃したのか分からない...そしてそれは私が探していたものです! – Hikaiix
代わりにsetQuadrilateralPointsを使用する必要があります。矩形を点の配列に変換する必要があります – svn
適用後に表示を更新します:page addAnnotation:およびPDFView setNeedsDisplay:YES – svn