Skip to main content
Participating Frequently
November 25, 2020
Answered

Empty space (without characters and lines) to place an annotation

  • November 25, 2020
  • 2 replies
  • 1370 views

Hello dear comunity,

what possibilities are there to find an empty space (without characters and lines) in a document, for example a drawing, automatically via JavaScript to set a annotation with known dimensions? I have already found a more or less common solution via getPageNthWordQuads and going through all words, but drawn elements are of course not covered by this. The annotation will be placed, but covers parts of the drawing.

Thank you very much in advance!

 

This topic has been closed for replies.
Correct answer Bernd Alheit

Not possible with Javascript code.

2 replies

Bernd Alheit
Community Expert
Bernd AlheitCommunity ExpertCorrect answer
Community Expert
November 25, 2020

Not possible with Javascript code.

Participating Frequently
November 25, 2020

Maybe via VBA together with API to Acrobat?

Bernd Alheit
Community Expert
Community Expert
November 25, 2020

May be possible with a plugin (written in C/C++) for Adobe Acrobat.

ls_rbls
Community Expert
Community Expert
November 25, 2020

I think you may need to be a little more specific. Maybe even share the code that that you're currently using.

 

When you say that you use getPageNthWordQuads  to go through all the words, what method are you implementing? Is the script employing "ckWord"?

 

As far as empty strings or spaces are you using any type of richText formatting in these annotations? Are these annotation free text annnotations or actual comments?

 

And when you mention about drawings are you referring to the shapes? (such as arrows, shapes, etc?)

 

 

Participating Frequently
November 25, 2020

Hello ls_rbls,

ok, sure, here one snippet:

var page = 0;
var StampH=110; //hight of the stamp
var StampB=240; //width of the stamp
var stringToSearchFor ="Date"; //the searched string to start the determination of the area, is specified by user at the beginning
var q = [0,0,0,0,0,0,0,0]; //Quad coordinates for one search string
var wortQ=[0,0,0,0,0,0,0,0]; //Quad coordinates for check string 
var deltaY=0;
var deltaX=0;
var pageRotation=this.getPageRotation(page); //drawings can be rotated, for this the transformation
var m = (new Matrix2D).fromRotated(this,page);
var mInv = m.invert();
//search for quads of search string and then take upper left corner, 
for (var n = this.getPageNumWords(page)-1; n >=0 ; n--) {
  if (this.getPageNthWord(page, n) == stringToSearchFor) {
  q = this.getPageNthWordQuads(page,n);
  q = mInv.transform(q); 
  q = q.toString();
  q = q.split(",");
  q[0]=parseFloat(q[0]);
  q[1]=parseFloat(q[1]);
  break;
  }
}
//search for strings (length >3 char) upper left corner if in area StampH x StampB
for (n = this.getPageNumWords(page)-1; n >=0 ; n--) {
  if (this.getPageNthWord(page, n).length>3){
    wortQ = this.getPageNthWordQuads(page,n);
    wortQ = mInv.transform(wortQ); 
    wortQ = wortQ.toString();
    wortQ = wortQ.split(",");
    wortQ[0]=parseFloat(wortQ[0]);
    wortQ[1]=parseFloat(wortQ[1]);
    deltaY=wortQ[1]-q[1];
    deltaX=q[0]-StampB/2;
    //if the distance to the next word more than 1.5*StampH save the last coordinates
    if (q[1]<wortQ[1] && deltaX<=wortQ[0] && (deltaX+1.2*StampB)>=wortQ[0] && deltaY<=1.5*StampH){
      if (deltaY>=StampH){
        break;
      }
    q[1]=wortQ[1];
    }
  }
}
q[1]=q[1]+StampH/2;
q = m.transform(q);
var StampX_Mid = q[0];
var StampY_Mid = q[1];
// apply the stamp
var annot = this.addAnnot({
  page: page,
  type: "Stamp",
  rotate: pageRotation,
  rect: [	StampX_Mid,
		StampY_Mid, 
		StampX_Mid, 
		StampY_Mid],
  AP: "#Stamp", //should be the name of an existing stamp
  });

 Please do not be too hard about the code 🙂

 

As far as empty strings or spaces are you using any type of richText formatting in these annotations? Are these annotation free text annnotations or actual comments?

The annotation is a stamp with known dimensions

 

And when you mention about drawings are you referring to the shapes? (such as arrows, shapes, etc?)

Yes i mean the shapes too, lines, pionts and so on.

 

Best Regards,

Evgenij