How to Get the Context Menu's Coordinates and Draw a Rectangle in PdfViewer
Environment
Product Version | Product | Author |
---|---|---|
2023.2.718 | RadPdfViewer for WinForms | Desislava Yordanova |
Problem
For a regular WinForms control painting a rectangle would be a straightforward task assuming you have calculated the coordinates. In the RadPdfViewer, however, this is more complex because the control works with a document, and any custom rendering must be applied to the document itself. This way these settings will be preserved and still available when you save or print the document. This article shows how you can get the top left location of the context menu and draw a rectangle in the WinForms PdfViewer.
Solution
We can achieve this task with the help of the RadPdfProcessing library. The library exposes convenient APIs for creating and editing PDF documents: PdfProcessing - Overview - Telerik Document Processing. For your actual scenario it will be necessary to work with the loaded inside the UI control document and modify it with the FixedContentEditor class. We can use the editor to paint a rectangle at a desired location.
PdfProcessing - FixedContentEditor - Telerik Document Processing
PdfProcessing - Colors and Color Spaces - Telerik Document Processing
After we edit the document, we need to reload it inside the control so that the changes are reflected. This is a sample implementation of the context menu item Click event: