I need to merge a new highlight that overlaps an existing highlight on any given PDF page…so the two will become one.
I’m using PDFViewWPF in .Net/C#.
I’m hoping for an easy API call to do it, and avoid have to do the math against the two Rect’s belonging to the existing two Highlights (annotations) in an effort to create a third based on their sums, and then delete the existing two.
I guess I’m just hoping for an existing “Merge Annot” command…otherwise I’ll be doing manual arithmetic on the the Rects belonging to both…to create a third.
I’m hoping for an easy API call to do it, and avoid
have to do the math against the two Rect’s belonging
to the existing two Highlights (annotations) in an
effort to create a third based on their sums, and then
delete the existing two. I guess I’m just hoping for
an existing “Merge Annot” command…otherwise I’ll be
doing manual arithmetic on the the Rects belonging to
both…to create a third.
Unfortunately, making a “merge” command to merge two highlight annotations is not so straightforward, since annotations are highly customizable. The two highlights could have conflicting colours, border styles, associated popup annotations, opacities, unique IDs, subject/title metadata, and so on. Also, if the two highlights have custom opacity or colour and also overlap, then a merge operation could change the appearance of the highlight.
For these reasons, the advised way to merge two highlight annotations into one would be to (as you describe) manually create a third highlight based on merged coordinates and then to delete the existing highlights. Note that you would probably want to verify that you’re correctly propagating all annotation properties when merging (you may want to see https://www.pdftron.com/pdfnet/docs/PDFNet/html/Methods_T_pdftron_PDF_Annots_Highlight.htm to get an idea of what to keep track of).
That said, could you go into more detail about why you’d like to merge highlight annotations at all? What problem are you trying to solve?
The business rules for the app I’m working on, that loads downloaded PDF’s, state that a new highlight that over-laps with an existing highlight, is to merge with it, thus creating a new single hi-light that is the same size as the total space of the original two.
I figured there was no easy way to do it, so I’m using some of the same code from an answer to another post I put up here a week ago, that in essance detects if a new highlight’s Rect overlaps and existing highlight. I’m then modifying it so that that both the existing Annot and the new Annot get passed to a MergeAnnots(Annot existing, Annot new) method, where the greater values (or lesser value depending on direction I guess) between the two for each of x1, y1, x2, y2 get used to create a new third Annot, and the properties of the existing annot are applied (color, notes etc.), and then the existing and new annots are deleted, leaving the “merged annot” as the one I want. It should work just fine, but I thought I’d see if there was a “canned” way to do it already.