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

Community Beginner ,
Nov 25, 2020

Copy link to clipboard

Copied

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!

 

Adobe Community Professional
Correct answer by Bernd Alheit | Adobe Community Professional

Not possible with Javascript code.

TOPICS
Acrobat SDK and JavaScript, How to

Views

40

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

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

Community Beginner ,
Nov 25, 2020

Copy link to clipboard

Copied

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!

 

Adobe Community Professional
Correct answer by Bernd Alheit | Adobe Community Professional

Not possible with Javascript code.

TOPICS
Acrobat SDK and JavaScript, How to

Views

41

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Nov 25, 2020 0
Adobe Community Professional ,
Nov 25, 2020

Copy link to clipboard

Copied

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?)

 

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 25, 2020 1
Community Beginner ,
Nov 25, 2020

Copy link to clipboard

Copied

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 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 25, 2020 0
Adobe Community Professional ,
Nov 25, 2020

Copy link to clipboard

Copied

Not possible with Javascript code.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 25, 2020 0
Community Beginner ,
Nov 25, 2020

Copy link to clipboard

Copied

Maybe via VBA together with API to Acrobat?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 25, 2020 0
Adobe Community Professional ,
Nov 25, 2020

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 25, 2020 1
Community Beginner ,
Nov 25, 2020

Copy link to clipboard

Copied

OK, thanks, but this is far from my skills and resources.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 25, 2020 0