Print Page | Close Window

Saving highlighted content automatically as images

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=2108
Printed Date: 29 Apr 25 at 4:37PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Saving highlighted content automatically as images
Posted By: vg2786
Subject: Saving highlighted content automatically as images
Date Posted: 21 Jan 12 at 11:53AM
Hello Everyone,
I have a pdf file in which some text and images are highlighted using highlight text(U) tool. Is there a way to automatically extract all the highlighted content as separate images and save it to a folder? I dont want readable text. I just want all the highlighted content as images. Thanks
I want to upload the sample file. But here there is no option to upload the sample file.
http://www.sendspace.com/file/hejhkp - http://www.sendspace.com/file/hejhkp



Replies:
Posted By: Ingo
Date Posted: 21 Jan 12 at 9:57PM
Hi!

No. It's not possible with a QuickPDF-function and i fear
you won't find any pdf-library on the world offering this
functionality. You can try to do it yourself WITH QuickPDF.
It will be the hardest stuff you ever done developing ;-)
Sorry...

Cheers and welcome here,
Ingo



Posted By: edvoigt
Date Posted: 23 Jan 12 at 4:58PM
Hi,

i think you are on a wrong way.

Instead of using a tool to highlight areas of interest use easy a screenshot-programm and you get images. I use for this http://screenpresso.com - http://screenpresso.com . A powerfull easy to use solution.

To extract the highlighted areas directly from PDF is a hard nut.

Cheers,

Werner


Posted By: AndrewC
Date Posted: 23 Jan 12 at 11:53PM
Here is some C# code that does the job.

private void ExtractAnnots_Click(object sender, EventArgs e)
    {
        int dpi = 300;
        Rectangle r;
        List<Rectangle> annotList = new List<Rectangle>();

        QP.LoadFromFile("samplefile.pdf", "");

        for (int p = 1; p <= QP.PageCount(); p++)
        {
            QP.SelectPage(p);  // Select the current page.
            QP.SetOrigin(1);   // Set origin to top left.

            annotList.Clear();

            for (int i = 1; i <= QP.AnnotationCount(); i++)
            {
                if (QP.GetAnnotStrProperty(i, 101) == "Highlight")
                {
                    r = new Rectangle((int)(QP.GetAnnotDblProperty(i, 105) * dpi / 72.0),  // x
                                      (int)(QP.GetAnnotDblProperty(i, 106) * dpi / 72.0),  // y
                                      (int)(QP.GetAnnotDblProperty(i, 107) * dpi / 72.0),  // w
                                      (int)(QP.GetAnnotDblProperty(i, 108) * dpi / 72.0)); // h

                    annotList.Add(r); // Add the bounding box to the annotation list for this page.

                    string s = String.Format("page={0}: x={1} y={2} w={3} h={4}\n", p, r.X, r.Y, r.Width, r.Height);
                    OutputTxt.AppendText(s);
                }
            }

            // Now we have a list of annotations for the current page.
            // Delete the annotations from the PDF in memory so we don't render them.

            for (int i = QP.AnnotationCount(); i >= 0;  i--)   
                QP.DeleteAnnotation(i);

            QP.RenderPageToFile(dpi, p, 0, "page.bmp");   // 300 dpi, 0=bmp
            Bitmap bmp = Image.FromFile("page.bmp") as Bitmap; 

            for (int i=0;i<annotList.Count;i++)
            {
                Bitmap cropped = bmp.Clone(annotList, bmp.PixelFormat);

                string filename = String.Format("annot_p{0}_{1}.bmp", p, i+1);
                cropped.Save(filename);
            }

            bmp.Dispose();
        }

        QP.RemoveDocument(QP.SelectedDocument());
    }



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk