[javascript] Cannot set name and modDate on annotation  SOLVED

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

Mathew
User
Posts: 567
Joined: Thu Jun 19, 2014 7:30 pm

[javascript] Cannot set name and modDate on annotation

Post by Mathew »

I'm trying to copy annotations between documents and ran into a limitation that's stymied me: If I set the name of an annotation, I cannot set the modification date, and vice versa.
  • If I create the new annotation with no modDate and try to set it later, it just overwrites the .name with the date and doesn't set the modDate.
  • If I create it with both the modDate and name, it sets the name to the modDate.
  • If I create it with only the name, and then try to set the modDate, it will overwrite the name with the date, and not set the modDate
Looking at the JS API, it shows both .modDate and .name as R/W.

To reproduce, run in the console:

Code: Select all

{
    let partyDate = new Date('1999-12-31T12:00:00');
    let partyAnn = this.addAnnot({
        // name won't stick if either date set
        name: 'Prince',
        type: 'FreeText',
        page: this.pageNum,
        richContents: [{text:'PARTY!', textColor:["RGB",0.5,0,1], textSize: 20}],
        rect: [100,50,180,70],
        width:0,
        // can set creationDate on new annotation
        creationDate: partyDate,
        modDate: partyDate,
        });
    // get name, modification date but Prince is not here
    console.println('Name:  '+partyAnn.name);
    console.println('Date:  '+partyAnn.modDate);
    console.println('Since: '+partyAnn.creationDate);
}
User avatar
Roman - Tracker Supp
Site Admin
Posts: 332
Joined: Sun Nov 21, 2004 3:19 pm

Re: [javascript] Cannot set name and modDate on annotation  SOLVED

Post by Roman - Tracker Supp »

Hi Mathew,
Thank you. It is a bug. It will be resolved in the next release of the Editor. In the meanwhile you can use this workaround:

Code: Select all

function myAddAnnot(doc, annotData)
{
	const newAnnot = doc.addAnnot(annotData);
	newAnnot.name = annotData.name;
	return newAnnot;
}

{
    let partyDate = new Date('1999-12-31T12:00:00');
    let partyAnn = myAddAnnot(this, {
        // name won't stick if either date set
        name: 'Prince',
        type: 'FreeText',
        page: this.pageNum,
        richContents: [{text:'PARTY!', textColor:["RGB",0.5,0,1], textSize: 20}],
        rect: [100,50,180,70],
        width:0,
        // can set creationDate on new annotation
        creationDate: partyDate,
        modDate: partyDate,
        });
    // get name, modification date but Prince is not here
    console.println('Name:  '+partyAnn.name);
    console.println('Date:  '+partyAnn.modDate);
    console.println('Since: '+partyAnn.creationDate);
}
Mathew
User
Posts: 567
Joined: Thu Jun 19, 2014 7:30 pm

Re: [javascript] Cannot set name and modDate on annotation

Post by Mathew »

Thank you Roman :)
User avatar
Dimitar - PDF-XChange
Site Admin
Posts: 2206
Joined: Mon Jan 15, 2018 9:01 am

[javascript] Cannot set name and modDate on annotation

Post by Dimitar - PDF-XChange »

:)