Skip to main content
Known Participant
Jan 19, 2017 9:00 AM UTC
Question

Removing formatting from selected text

Hello,

I have written a plugin to select highlighted text from PDF document.

However,text I get from PDF document is retrieved with actual formatting, for example, new line etc.

I want the text without any formatting.

Here is the code snippet to get the highlight annotated text.

Here is my code for getting the annotated text:

  1. ACCB1 ASBool ACCB2 pdTextSelectEnumTextProc(void* procObj, PDFont font, ASFixed size, PDColorValue color, char* text, ASInt32 textLen) 
  2. { 
  3.   char stringBuffer[200]; 
  4.   strcpy(stringBuffer, text); 
  5.   ss << stringBuffer; 
  6.   return true; 
  7. } 

  1. if (ASAtomFromString("Highlight") == PDAnnotGetSubtype(annot)) 
  2.   { 
  3.   // Gets the annotation's rect 
  4.   PDAnnotGetRect(annot, &boundingRect); 
  5.   // Gets the text selection from the annotation's rect 
  6.   PDTextSelect textSelect = PDDocCreateTextSelect(pdDoc, pageNum, &boundingRect); 
  7.   // create a callback to get the text from highlighted bounding box 
  8.   PDTextSelectEnumText(textSelect, ASCallbackCreateProto(PDTextSelectEnumTextProc, &pdTextSelectEnumTextProc), &annBuf); 
  9.  
  10.   MessageBox(NULL, ss.str().c_str(), NULL, NULL); 
  11.   } 


String stream contains the string with all formatting.

How can I get the text without any formatting?

Thanks

This topic is closed to new replies. Start a new post to keep the conversation going.

6 replies

Legend
Jan 19, 2017 2:11 PM UTC

You mentioned ellipsis (...) in some other post I think? If so we should consider that in Latin1 encodings that 0x85 is an ellipsis (single character for three dots). It is not layout.

Translate
Legend
Jan 19, 2017 12:09 PM UTC

What are the hex values?

Translate
Known Participant
Jan 19, 2017 12:10 PM UTC

Sorry I did not get. Which hex values do you mean?

Translate
Known Participant
Jan 19, 2017 1:12 PM UTC

Hello,

I did some debugging. Hex value is x85

Translate
Legend
Jan 19, 2017 11:46 AM UTC

1. You do not check the string length before strcpy. This is a serious bug.

2. If you don't want newlines you can strip them or change them to spaces.

Translate
Known Participant
Jan 19, 2017 11:58 AM UTC

I am not able to replace the new line with any other character.

I am comparing each word with \n\r, It seems that PDF formatting character is different for new line.

I can't see \n or \r in the text when I compare.

Please tell me how can I strip them?

Thanks.

Translate