Copy link to clipboard
Copied
In pdf ,
I want to Create hyperlink on all numbers with dot (.) (1. , 2. , etc..)
This number will be in the starting of paragraph which has destination with same number with #
Note destination number with # can be on different page
+++++++
Below is the code..
// Iterate through all pages of the PDF
for (var pageNum = 0; pageNum < this.numPages; pageNum++) {
var page = this.getPageNum(pageNum);
var pageText = page.extractText();
// Use a regular expression to find numbers with dots at the beginning of paragraphs
var numberRegex = /^\d+\./gm;
var match;
while ((match = numberRegex.exec(pageText)) !== null) {
// Extract the matched number with dot
var numberWithDot = match[0];
/////////// Hyperlink and hyperlink destination code will come here .....
}
}
++++++
Error
this.getPageNum(pageNum) is not a function
tried alternative,
this.getNthPage(pageNum)
this.getNthPage(pageNum) is not a function
How do I exactly get the content of the page and match it with regex. Please help.
In the indesign script there is a doc.findGrep() function which makes life easier. How do I achieve this in PDF?
Thanks for the support.
Copy link to clipboard
Copied
Thanks @APK33396881raev .
As already mentioned in the post,
It throws me an error as below
this.getPageNum(pageNum) is not a function
Also tried,
this.getNthPage(pageNum) is not a function
Is there any alternative to get exact content which matches regex from page..
I want content from whole file which matches regex, which I can loop through and not necessarily from page by page.
Please suggest.
Copy link to clipboard
Copied
getPageNum and extractText doesn't exist in Acrobat Javascript.
Copy link to clipboard
Copied
Thank you @Bernd Alheit
Yes , while using it getting error
this.getPageNum(pageNum) is not a function
Also tried,
this.getNthPage(pageNum) is not a function
Is there any alternative to get exact content which matches regex from page..
I want content from whole file which matches regex, which I can loop through and not necessarily from page by page.
Please suggest.
Copy link to clipboard
Copied
You must create loops over all words in the file.
Read the documentation in the Acrobat Javascript Reference.
Copy link to clipboard
Copied
Also tried the getPageNthWord() function. so that I can iterate through all the words and match each word with regex. but getPageNthWord() omits the special character like (.) dot, # etc.
Is there any alternative with this logic.? Please suggest
// Iterate through all pages of the PDF
for (var pg = 0; pg < this.numPages; pg++) {
var numwords = this.getPageNumWords(pg);
for (var i=0; i < numwords; i++)
{
console.println(this.getPageNthWord(pg,i));
}
}
Copy link to clipboard
Copied
How do I search for string with dot(.) and hash (#). Any code or regex. As getnthword omit the special characters.
How do I match
Want to Create link on each number
1.
2.
3.
..
Destination would be on..
1#
2#
3# in same file..
Just need to iterate all words match with string and create link and destination accordingly.
Please guide.
Copy link to clipboard
Copied
Look at the parameters of function getPageNthWord.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Thank you, able to find the words with specific pattern s
Is there any way to create link destination and hyperlink using javascript..?
I want to Create hyperlink on all numbers with dot (.) (1. , 2. , etc..)
This number will be in the starting of paragraph which has destination with same number with # (1#, 2#, ...)
Note destination number with # can be on different page