1

I read a lot of books in PDF format and highlight them. I then extract all the highlights and use them to study.

I would like to be able to do this with images too - but I don't just want to extract all the images - I want to extract the specific portion that I've drawn a rectangle around. In the sample image that I made, below, I'd like to just extract the chunk of code within the red rectangle - to a JPG or stream or something I can manipulate in the study software I'm writing.

Does anyone know of an SDK that allows this? It seems I should be able to identify the rectangles in the PDF file and their coordinates - and then extract an image based on those coordinates - but I've not been able to find anyone doing this. Worst case, how can I identify an image I've drawn a rectangle around and extract the image beneath it - in this case the entire Visual Studio image?

I'm using the SyncFusion PDF solution to extract the highlighting. I've tinkered with ITextSharp. It's possible one of these may do it - but I haven't figured out how (yet).

Thanks.

P.S. Page is from an excellent book called "The C# Player's Guide" by RB Whitaker

enter image description here

1
  • Don't have enough rep to comment, so I'll ask for details here: 1. How exactly do you draw the "highlight" rectangle on the image? 2. Can you share a small PDF file with a highlighted image? – PDF Programmer Apr 23 '18 at 6:48
1

You can extract a rectangular region from an image using Leadtools. As a disclaimer, I work for LEAD Technologies that develops this toolkit. If you are displaying the image in an ImageViewer, you can use the ImageVeiwerAddRegionInteractiveMode to allow the user to select a region with their mouse. You can then copy the region to a second imageViewer using the following code, which is set in the WinForms Form constructor:

var regionInteractiveMode = new ImageViewerAddRegionInteractiveMode
{
    Shape = ImageViewerRubberBandShape.Rectangle,
};

regionInteractiveMode.WorkCompleted += (s, e) =>
    {
        if (imageViewer.Floater != null)
    {
        imageViewer2.Image = imageViewer.Floater.Clone();
        imageViewer.Floater.MakeRegionEmpty();
        var region = imageViewer2.Image.GetRegion(null);
        imageViewer2.Image.MakeRegionEmpty();
        imageViewer2.Image.SetRegion(null, region, RasterRegionCombineMode.SetNot);
        new FillCommand(RasterColor.White).Run(imageViewer2.Image);
        imageViewer2.Image.MakeRegionEmpty();
    }
};

imageViewer.InteractiveModes.BeginUpdate();
imageViewer.InteractiveModes.Add(regionInteractiveMode);
imageViewer.InteractiveModes.EndUpdate();

You should get a result similar to this: Sample application

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.