Copy link to clipboard
Copied
Hello,
Is it possible to help me with a program?
I would like to delete in a table all the texts containing a "Yy" prefix like the words "Yycar", "Yytravel", etc...
I developped a code but it doesn't seem to work at runtime, if you have a track I will be totally grateful to you 🙂
Here is my code:
// recovery. of all <td>
const oCells = document.querySelectorAll("table td");
const search = "Yy";
// the search loop
for (let cell of oCells) {
const text = cell.textContent; // reading raw content
if (text.startsWith(search)) { // occurrence found
cell.textContent = " "; // we replace the content with nothing
}
}This JavaScript code will be used on a PDF document containing a table with data and I would like to delete in this table all the texts containing the prefix "Yy".
Thanks in advance for your reply and have a nice day!
Copy link to clipboard
Copied
This is not Acrobat JavaScript. It's got a browser.
Copy link to clipboard
Copied
This is not Acrobat JavaScript. It's got a browser.
By @Test Screen Name
Do you have a solution in this case?
Copy link to clipboard
Copied
Not sure what case this is...
- you have a question about browsers but you are in the wrong place?
- you want to work in Acrobat but have the wrong JavaScript?
Please let us know.
Copy link to clipboard
Copied
Not sure what case this is...
- you have a question about browsers but you are in the wrong place?
- you want to work in Acrobat but have the wrong JavaScript?
Please let us know.
By @Test Screen Name
I will explain my case.
I first on Word generate a table pre-filled with data using a macro. Following this I exported my table as a PDF file.
And I have a javascript function which allows to remove all the fields from my table which do not contain the "Yy" prefix.
Now what I will need is to remove the texts containing the prefix "Yy" which are placed in front of the fields so that they only have the text. And when I say delete the texts, it means replacing the text with "".
Here is my table :
I used field recognition to make all fields appear in the table. Then with a javascript function I deleted all the fields not containing the "Yy" prefix as you can see.
And now I would like to delete the texts in front of the fields.
Here is the code to delete all the fields not containing the "Yy" prefix :
for (var i=this.numFields-1; i>=0; i--) {
var f = this.getField(this.getNthFieldName(i));
if (f==null) continue;
if (/^Yy/.test(f.name)) continue;
this.removeField(f.name);
}
Copy link to clipboard
Copied
Photo after executing the function which removes all the fields which do not contain the "Yy" prefix.
Copy link to clipboard
Copied
Acrobat Javascript can't change the text in PDF files. Can't you change the text in the Word document?
Copy link to clipboard
Copied
Unfortunately not because as I say on word I created a pre-filled table with data in some cells starting with "Yy". And the cells contain names for that when I export my file to PDF. The fields automatically take the name of the cell data with the field recognition tool.
Copy link to clipboard
Copied
If Acrobat Javascript can't change texts in a PDF document, can it at least hide / hide them?
Copy link to clipboard
Copied
I forgot to specify I am on Foxit PhantomPDF and I can modify the texts of a PDF on it.
Like this :
But I would like to automate this action with JavaScript ...
Copy link to clipboard
Copied
Try a forum for Foxit PhantomPDF.
Copy link to clipboard
Copied
Ok thanks for your answer, I will do that.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more