Hi,
My team is working on a cross-platform app that allows sharing of highlights and annotations made on PDF docs, across multiple platforms. This is how I’ve been doing it so far:
private ToolManager _pdfToolManager;
private PDFViewWPF _pdfViewer;
private Tool _highlightTool;
private Annot _newAnnot;
private Boolean _newAnnotationAdded;
.
.
.
public void LoadToolManager()
{
_pdfToolManager = new ToolManager(_pdfViewer);
_pdfToolManager.IsEnabled = true;
_pdfToolManager.AnnotationAdded += PdfToolManager_AnnotationAdded;
//Turn on highlighting…it’s always available.
ListenForHighlights();
PdfViewer.OnSetDoc += PdfViewer_OnSetDoc;
}
private void ListenForHighlights()
{
_highlightTool = _pdfToolManager.CreateTool(pdftron.PDF.Tools.ToolManager.ToolType.e_text_highlight, null, true);
_pdfViewer.MouseLeftButtonUp += PdfViewer_MouseLeftButtonUp;
_pdfViewer.MouseLeftButtonDown += PdfViewer_MouseLeftButtonDown;
_pdfViewer.MouseDoubleClick += PdfViewer_MouseDoubleClick;
_pdfViewer.CurrentPageNumberChanged += PdfViewer_CurrentPageNumberChanged;
}
private void PdfToolManager_AnnotationAdded(Annot newAnnot)
{
_newAnnot = newAnnot; //there is a single annot for the highlight (x1, y1, x2, y2)
_newAnnotationAdded = true;
}
This all works fine, and I was creating a capturing highlights based on the entire Rect area of the mouse down/up area (which is recorded as x1, y1, x2, y2). A member of the Android team is now telling this won’t do because if the user starts with a sentence that begins in the middle of one line, and ends in the middle of a line, 3 lines down, then a singular Rect is created for the total 4 lines, and includes text not specifically selected by the user (and outside of the sentence selected), it just creates one large rect for the entire x/y area.
So I have to now rethink my approach…
He suggested I look at the “SelectText” method of the ToolManager, which will deliver separate Rects for each line, which equates to an array of Rects for a single highlight…thus allowing the first and last Rects to only capture the text the user intended (the start and ends of the sentence) and ignore everything else on those respective lines.
Any samples on the easiest way to implement this ? I’m hoping to not have to re-write the entire thing…but just change which tool I’m using, and have a way to capture the created Rects after the mouse button comes up. All highlights created are saved to a database, and shared across devices…and our app loads them back up again when the doc is loaded into the PDFviewer.
I’m using .Net, C#, PDFViewWPF
This is an example similar to what I’m describing. The approach above will capture everything in the outlined dotted box…when what I really want is just what was actually highlighted in yellow !
Thanks,
Barry