Ticket T319354
Visible to All Users

PDF Viewer Highlight text in different colors.

created 9 years ago

How to save or capture highlighted PDF text using PDF viewer. Basically is there way to do color coded Highlighted text. Please advise. Thanks

Comments (2)
DevExpress Support Team 9 years ago

    Hello Haruun,

    Would you please clarify the task you trying to accomplish? Do you want to highlight text in the PDFViewer control or save highlighted text in the PDF document?

    Thanks.
    Elliot

    HM HM
    Haruun Mohamud 9 years ago

      I would like to accomplish both. I can highlighted, but how do I change the color or supply different color for the highlighted text.  Then I would like to save it. I can open window asking user to save it, but I am not sure if the highlighted text will stay highlighted. Thanks for the feedback.

      Answers approved by DevExpress Support

      created 9 years ago

      Hello Haruun,

      Thank you for your clarification. You can use the PdfDocumentProcessor.FindText method to find text in the PDF document. Then, call the PdfViewerControl.ConvertDocumentPositionToPixel method to get coordinates of a point corresponding to a document position and call the PdfGraphics.FillPolygon method to highlight text in the PDF Document.

      Thanks,
      Elliot

      PS. Please note that the PDFDocumentProcessor control is located in two packages: Universal Subscription and .NET Document Automation. So, it is necessary to have a license for one of these subscriptions to be able to use PDFDocumentProcessor in the application.

        Show previous comments (4)
        DevExpress Support Team 9 years ago

          Hello,

          The cause of this behavior is that multiline text is surrounded by several rectangles. Thus, the PdfTextSearchResults.Rectangles property contains more than one item. To overcome the issue, modify the code Mariya provided to calculate the correct location of the text. Modify the DrawGraphics method in Mariya's project for this purpose.

          C#
          static void DrawGraphics(PdfGraphics graph, PdfTextSearchResults result, SolidBrush brush) { ..

          Should you have any questions or concerns while implementing this approach, let me know.

          HM HM
          Haruun Mohamud 9 years ago

            Can provide example how to modify the drawing using your method.  The way I did works, but I am interested to see how your method will work. Thanks for the quick feedback.

            DevExpress Support Team 9 years ago

              A possible implementation of the DrawGraphics method to highlight multiline text may look like this:

              C#
              static void DrawGraphics(PdfGraphics graph, PdfTextSearchResults result, SolidBrush brush) { for (int i = 0; i < result.Rectangles.Count; i++) { RectangleF rect = new RectangleF(new PointF((float)result.Rectangles[i].Left, (float)result.Page.CropBox.Top - (float)result.Rectangles[i].Top), new SizeF((float)result.Rectangles[i].Width, (float)result.Rectangles[i].Height)); graph.FillRectangle(brush, rect); } graph.AddToPageForeground(result.Page, 72, 72); }

              I have modified Mariya's previous project to demonstrate the approach in action. You can find the project in the attachment.

              I hope you will find my sample useful.

              Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

              Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.