Toby
asked on 11 Oct 2023, 10:01 AM
| edited on 11 Oct 2023, 10:05 AM
Hi, I have a need for the user to be able to select an rectangular area from a PDF page from within the PDF viewer and then to extract this area as an image. Is this possible? If so how?
1 Answer, 1 is accepted
0
Dinko | Tech Support Engineer
Telerik team
answered on 12 Oct 2023, 11:36 AM
Hi Toby,
Thank you for your interest in our RadPdfViewer control.
I will start with that the control does not provide such functionality of the box. However, you could try to implement custom code to implement your requirements. Here is what I have in mind.:
How to Get the Context Menu's Coordinates and Draw a Rectangle in PdfViewer: You can start from here. This KB article demonstrates how to draw a rectangle on mouse click position with a given width and height via the context menu. Now you could extend the approach depending on how the user needs to draw the rectangle.
Then you can export the page to an image. You can check the Export to image help article.
The last step is to crop the part where the rectangle was drawn. You can check this StackOverflow thread or search for a similar approach: How do I crop an image using C#?
I think the main obstacle will be to transfer the correct x,y starting point of the drawn rectangle to the image/bitmap image coordinates. I am afraid that I don't have a complete solution for your scenario, but I think the above resources will be a good starting point.
I hope that you find my reply helpful.
Regards,
Dinko | Tech Support Engineer
Progress Telerik