Copy over text content of multiple comments through comment pane

Forum for the PDF-XChange Editor - Free and Licensed Versions

Moderators: Daniel - PDF-XChange, PDF-XChange Support, Vasyl - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Paul - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

Post Reply
MedBooster
User
Posts: 1372
Joined: Mon Nov 15, 2021 8:38 pm

Copy over text content of multiple comments through comment pane

Post by MedBooster »

When I select all these typewriter comments – and copy them (Ctrl+C), they are copied in the software itself, and I am able to paste them into other pages or document in PDF-XCE, HOWEVER the text content is not copied, so I can't simply copy over all the text content of the typewriter comments this way, which too bad...
image.png

"related" question about base content
viewtopic.php?p=187098#p187098
My wishlist https://forum.pdf-xchange.com/viewtopic.php?p=187394#p187394
Disable SPACE page navigation, fix kb shortcut for highlighting advanced search tool search field, bookmarks with numbers, toolbar small icon size, AltGr/Ctrl+Alt keyboard issues
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 10897
Joined: Wed Jan 03, 2018 6:52 pm

Re: Copy over text content of multiple comments through comment pane

Post by Daniel - PDF-XChange »

Hello, MedBooster

A comment export can only contain comment data, and the "text annotation" tools, such as highlight and underlines are applied to "base content" text items, not comments. This means that the comment you see on the page is only the underline or highlight mark, and has no relation to the text below it.

One way to alleviate this issue is to enable the following option in our preferences (Ctrl_K), which will duplicate the selected text into the "comment popup" data of the item.
MHOb4FA43oSabRKp.png
This way, when you export/import the comment, the underlying text will be present inside of the comment data, visible by double clicking on the existent comment object. (note that this option is not recursive, meaning):
1. It will not make any comments you have already placed suddenly contain this data
2. If you make changes to highlighted/underlined text after the comment is placed, the comment will not be updated automatically with the new text.

Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
MedBooster
User
Posts: 1372
Joined: Mon Nov 15, 2021 8:38 pm

Re: Copy over text content of multiple comments through comment pane

Post by MedBooster »

this is for newly created textboxes/typewriter comments...

but if you were to want to copy the content of a few textboxes by selecting the comments, it only copies the comments , but not the text from within the comments is not shown in the clipboard. Is there a way to enable this?

XMind (mindmapping software) is a great example of this – when you copy multiple branches or paragraphs they are
1) copied to your clipboard with correct indent formatting
2) as well as retaining the formatting in case your goal is to paste the formatted text back into the same or another XMind document...
IDK how it works, but somehow it works, that the clipboard just receives the information, but that the program is able to read into the formatting (which is not visible in the clipboard, or when pasted)
Notion (notetaking program) is an example where you copy over text, where headings etc. are formatted with different symbols e.g. #, this I would not want....

Currently it seems that you either have to export the comments, or convert them to base content –––––––––––
otherwise it seems that you have to go double-click and select the text within each comment manually... hmm...

3) so my specific request is that textboxes you copy (not the text within) , also should send the content to your clipboard (or at least there should be an option to enable/disable this behavior).
My wishlist https://forum.pdf-xchange.com/viewtopic.php?p=187394#p187394
Disable SPACE page navigation, fix kb shortcut for highlighting advanced search tool search field, bookmarks with numbers, toolbar small icon size, AltGr/Ctrl+Alt keyboard issues
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 10897
Joined: Wed Jan 03, 2018 6:52 pm

Re: Copy over text content of multiple comments through comment pane

Post by Daniel - PDF-XChange »

Hello, MedBooster
MedBooster wrote: Wed Nov 27, 2024 6:49 pm this is for newly created textboxes/typewriter comments...
Yes, I did mention that caveat at the end of my previous post. Unfortunately in PDF, there is no direct association of the two content types, and so selecting/copying them with assumption of relation/adjacency is not currently possible.
MedBooster wrote: Wed Nov 27, 2024 6:49 pm but if you were to want to copy the content of a few textboxes by selecting the comments, it only copies the comments , but not the text from within the comments is not shown in the clipboard. Is there a way to enable this?
The clipboard holds a multitude of different data formats. When we copy a group of comments, the "text" present inside of the comment itself is included, but the base content page text is not able to be copied alongside it. If you paste those comments into another PDF, the originally present text comment data will still be present (simply double click on the comment to open and view any text contents associated with the comment).

Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
MedBooster
User
Posts: 1372
Joined: Mon Nov 15, 2021 8:38 pm

Re: Copy over text content of multiple comments through comment pane

Post by MedBooster »

Copied over from here viewtopic.php?p=187843#p187843
(this thread is more relevant for the discussion)

hmmm... I've only tried export selection to Word, which just gave me nonsensical (no letters characters) output... – from textboxes

Comment Tab> Summarize Comments. Macros
can be used in the Filename text box.
1)
Please help me understand what I need to tick if I ONLY want text output
Not even comment names, just the text content within the comments (sticky notes, text boxes, etc...)

2)
How do I make this apply to ONLY comments selected in the document, or in the comments pane?
image.png
My wishlist https://forum.pdf-xchange.com/viewtopic.php?p=187394#p187394
Disable SPACE page navigation, fix kb shortcut for highlighting advanced search tool search field, bookmarks with numbers, toolbar small icon size, AltGr/Ctrl+Alt keyboard issues
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 10897
Joined: Wed Jan 03, 2018 6:52 pm

Re: Copy over text content of multiple comments through comment pane

Post by Daniel - PDF-XChange »

Hello, MedBooster

First, your mention of "nonsensical" characters, could I ask for a copy of the original PDF, and your export with these settings? (Also, just to be sure I am testing the same function, can you show me how exactly you have selected "export selection to word"?

1) You appear to have removed as much information as is possible with the settings you have shown there, no more would be possible.

2) It is not currently possible to summarize only the selected comments. Summaries are for all comments on the defined pages, specifically.

Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
Mathew
User
Posts: 563
Joined: Thu Jun 19, 2014 7:30 pm

Re: Copy over text content of multiple comments through comment pane

Post by Mathew »

[edit] see the script in the next post for an improved approach.

Here's a script that came together as a result of a discussion in another topic. It adds a toolbar button, so could be saved as a javascript file (.js suffix) in the Javascripts folder. I've not bothered to make an icon for it, so if someone has time, feel free.

It gets the text inside all the selected comments, and outputs it to a new document text field. Bullet and numbered lists don't work too well - I don't think PXE supports them in text fields:

Code: Select all

// get text from multiple comments
// v0.2 2024-12-11 added delimiter to the function parameters, so can more easily change it
// v0.1 2024-12-11 by mathew for forum https://forum.pdf-xchange.com/viewtopic.php?t=44623 

app.addToolButton({
    cName: "getMultiAnnotTx",
    cLabel: "Get Text",
    cTooltext: "Get the text from the selected annotations, and return in a new document.",
    cEnable: "event.rc = (this.selectedAnnots && this.selectedAnnots.length)",
    //cIconID: 'ico.find', // a built-in icon
    cExec: "getTextMultipleAnnots(this, '\\n');"
});

var getTextMultipleAnnots = (function() {
  
  // this requires privelige if done outside the console
  const newDoc = app.trustedFunction((...args) => {
      app.beginPriv();
      return app.newDoc(...args);
  });
  
  // return the function
  return (doc, delim = '\n') => {
    // get the selected comments
    const selAnns = doc?.selectedAnnots;
    if (!selAnns?.length) return; // nothing selected
    
    // loop through them and add their contents
    const allText = [];
    for (const c of selAnns) {
        const txt = c.contents;
        // delim - there will always be contents, even if there's richContents
        if (allText.length && txt) allText.push({text: delim});
        // richContents (formatted text)
        const rTxt = c.richContents;
        if (rTxt) {
            // add the rich contents
            allText.push(...rTxt);
        } else if (txt) {
            // add a simple span with this text
            allText.push({
                text: txt,
                fontFamily: c.textFont,
                textSize: c.textSize});
        }
    }
    
    // can't access the clipboard, so make a new document with a form field
    const pgBox = doc.getPageBox({nPage: doc.pageNum});
    const nWidth = pgBox[2] - pgBox[0];
    const nHeight = pgBox[1] - pgBox[3];
    
    // new temporary document
    const tDoc = newDoc({ nWidth, nHeight});
    
    // add a form field with the contents of the annots
    const newField = tDoc.addField({
        cName: 'Annotation_text',
        cFieldType: 'text',
        nPageNum: 0,
        oCoords: pgBox, // lazy - should be transformed
        });
        
    // set properties of field
    newField.multiline = true;
    newField.richText = true;
    newField.richValue = allText;

    // also return the text
    return allText;
  };
})();
Last edited by Mathew on Tue Dec 17, 2024 4:41 pm, edited 2 times in total.
Mathew
User
Posts: 563
Joined: Thu Jun 19, 2014 7:30 pm

Re: Copy over text content of multiple comments through comment pane

Post by Mathew »

MedBooster wrote: Wed Nov 27, 2024 6:49 pm 3) so my specific request is that textboxes you copy (not the text within) , also should send the content to your clipboard (or at least there should be an option to enable/disable this behavior).
I just had an idea: Once the information is in a field, we can set the focus to that field, and run the built-in copy command: voilà! All the text, including formatting, is in the clipboard :shock:

Code: Select all

/** Tool to get text from multiple comments
  *
  * History:<pre>
  * v0.3 2024-12-11 copy text to the clipboard, add closeTemp parameter
  * v0.2 2024-12-11 added delimiter to the function parameters, so can more easily change it
  * v0.1 2024-12-11 by mathew for forum https://forum.pdf-xchange.com/viewtopic.php?t=44623</pre>
**/

app.addToolButton({
    cName: "getMultiAnnotTx",
    cLabel: "Get Text",
    cTooltext: "Get the text from the selected annotations, and return in a new document. Also copies the text to clipboard. It returns the text in the order that the annotations were selected.",
    cEnable: "event.rc = (this.selectedAnnots && this.selectedAnnots.length)",
    cIconID: 'ico.text', // a built-in icon
    cExec: "getTextMultipleAnnots(this, '\\n');"
});

/** @function getTextMultipleAnnots
  * @param {object} doc - the document to get annotations from
  * @param {string} [delim] - delimiter between text from different annotations (default newline '\n')
  * @param {boolean} [closeTemp] - true to close the temporary document after copying (default false)
**/

var getTextMultipleAnnots = (function() {
  
  // this requires privelige if done outside the console
  const newDoc = app.trustedFunction((...args) => {
      app.beginPriv();
      return app.newDoc(...args);
  });
  
  // return the function
  return (doc, delim = '\n', closeTemp = false) => {
    // get the selected comments
    const selAnns = doc?.selectedAnnots;
    if (!selAnns?.length) return; // nothing selected
    
    // loop through them and add their contents
    const allText = [];
    for (const c of selAnns) {
        const txt = c.contents;
        // delim - there will always be contents, even if there's richContents
        if (allText.length && txt) allText.push({text: delim});
        // richContents (formatted text)
        const rTxt = c.richContents;
        if (rTxt) {
            // add the rich contents
            allText.push(...rTxt);
        } else if (txt) {
            // add a simple span with this text
            allText.push({
                text: txt,
                fontFamily: c.textFont,
                textSize: c.textSize});
        }
    }
    
    // can't access the clipboard, so make a new document with a form field
    const pgBox = doc.getPageBox({nPage: doc.pageNum});
    const nWidth = pgBox[2] - pgBox[0];
    const nHeight = pgBox[1] - pgBox[3];
    
    // new temporary document
    const tDoc = newDoc({ nWidth, nHeight});
    
    // add a form field with the contents of the annots
    const newField = tDoc.addField({
        cName: 'Annotation_text',
        cFieldType: 'text',
        nPageNum: 0,
        oCoords: pgBox, // lazy - should be transformed
        });
        
    // set properties of field
    newField.multiline = true;
    newField.richText = true;
    newField.richValue = allText;
    
    // focus on this field and run the built-in copy command
    newField.setFocus();
    app.execMenuItem('cmd.copy', tDoc);
    
    // close the temporary document
    if (closeTemp) tDoc.close(true);

    // also return the text
    return allText;
  };
})();
btw: If autohotkey can run a javascript directly, you could maybe assign a shortcut to an autohotkey script to run the function: getTextMultipleAnnots(this, '\n', true); and it will close the temporary document also, with just the information you want in the clipboard.
Last edited by Mathew on Mon Dec 16, 2024 5:50 pm, edited 1 time in total.
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 10897
Joined: Wed Jan 03, 2018 6:52 pm

Re: Copy over text content of multiple comments through comment pane

Post by Daniel - PDF-XChange »

Hello, Mathew

Thank you for sharing all of this, I was expecting medbooster to come back, but It seems they have other objectives to attend to!

Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
Mathew
User
Posts: 563
Joined: Thu Jun 19, 2014 7:30 pm

Re: Copy over text content of multiple comments through comment pane

Post by Mathew »

:lol:
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 10897
Joined: Wed Jan 03, 2018 6:52 pm

Copy over text content of multiple comments through comment pane

Post by Daniel - PDF-XChange »

:)
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
MedBooster
User
Posts: 1372
Joined: Mon Nov 15, 2021 8:38 pm

Re: Copy over text content of multiple comments through comment pane

Post by MedBooster »

Mathew wrote: Mon Dec 16, 2024 5:51 pm:lol:
VERY good work
would you happen to have any instructions on how to add a custom icon for javascript add-ons? maybe you could open a thread with an explanation or something?

should the icon be .ico, .png or .jpeg?

What are all the numbers for? For example:

Code: Select all

// isolate annotations
var myIcon = {count:0, width:20, height:20, read:function(nBytes=this.data.length/2){return this.data.slice(this.count,this.count+=2*nBytes)}, data:"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000FF0A61B3FF0A61B3FF0A61B3FF0A61B3FF0A61B3FF0A61B3FF0A61B3FF5491CA0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000FF0A61B3FFD9ECF5FFD9ECF5FFD9ECF5FFD9ECF5FFD9ECF5FFD9ECF5FF0A61B30000000000000000000000000000000000000000000000000000000000000000000000000000000000000000FF0A61B3FFACD5E7FFACD4E7FFACD4E7FFACD4E7FFACD4E7FFACD4E7FF0A61B30000000000000000000000000000000000000000000000000000000000000000000000000000000000000000FF0A61B3FFB6DAEAFFB6DAEAFFB6DAEAFFB6DAEAFFB6DAEAFFB6DAEAFF0A61B3FF636972FF636972FF92969D0000000000000000000000000000000000000000000000000000000000000000FF0A61B3FFC1DFEDFFC1DFEDFFC1DFEDFFC1DFEDFFC1DFEDFFC1DFEDFF0A61B3FFF8F9FAFFF8F9FAFF6369720000000000000000FF000000FF000000FF000000000000000000000000000000FF5491CAFF0A61B3FF0A61B3FF0A61B3FF0A61B3FF0A61B3FF0A61B3FF0A61B3FFEEF0F2FFEEF0F2FF63697200000000000000000000000000000000FF000000FF0000000000000000000000000000000000000000000000FF636972FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF636972FF636972000000000000000000000000FF00000000000000FF00000000000000000000000000000000000000FF636972FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF63697200000000000000000000000000000000FF000000000000000000000000000000000000000000000000000000FF92969DFF464B52FF464B52FF464B52FF464B52FF464B52FF464B52FF6369720000000000000000FF00000000000000FF0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000FF000000FF000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000FF000000FF000000FF000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"};
My wishlist https://forum.pdf-xchange.com/viewtopic.php?p=187394#p187394
Disable SPACE page navigation, fix kb shortcut for highlighting advanced search tool search field, bookmarks with numbers, toolbar small icon size, AltGr/Ctrl+Alt keyboard issues
Mathew
User
Posts: 563
Joined: Thu Jun 19, 2014 7:30 pm

Re: Copy over text content of multiple comments through comment pane

Post by Mathew »

MedBooster wrote: Thu Dec 19, 2024 12:22 pm would you happen to have any instructions on how to add a custom icon for javascript add-ons? maybe you could open a thread with an explanation or something?
viewtopic.php?t=44829
Post Reply