Add hyperlinks through Javascript in a large pdf document
Hello everyone,
I am working on adding hyperlinks in a large .pdf document (over 4000 pages).
JS Script is doing the job, except the execution time is around 4h. I imagine there is a faster technical solution to do the same thing. I guess just the double for loop is ruining it.
Looking at the messages in otherr discussions, it seems the document is a bit large to use JS from Adobe
Is there any proper solution to make the script faster? Any other way? Anything obviously stupid in the code below?
Thank you so much,
Xavier
//go through document page by page
for (var p = 0; p < this.numPages; p++)
{
//get number of words in the page
var numWords = this.getPageNumWords(p);
for (var i = 0; i<numWords; i++)
{
var Word = this.getPageNthWord(p, i, true);
if (this.getPageNthWord( p, (i+1), true) != null)
{
var NextWord = this.getPageNthWord(p, (i+1), true);
//Detect Word "Model" and number of characters after this model
if (Word == "Model")
{
if ( (NextWord.length == 12) &e
& (NextWord.indexOf(".") > -1) )
{
//add link on the detected zonvar q = this.getPageNthWordQuads(p, (i+1));
m = (new Matrix2D).fromRotated(this,p);
mInv = m.invert();
r = mInv.transform(q);
r = r.toString();
r = r.split(",");
l = addLink(p, [r[4], r[5], r[2], r[3]]);
var HTMLFile = NextWord.replace(".","_") + "/" + NextWord.replace(".","_") + "_view.html";
l.setAction("Myscript(this.path.substr(0,this.path.lastIndexOf(\"/\")) + \"/2 - Database files/HTML Files/" + HTMLFile + "\");");
}
}
}
}
}
