Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

[HELP JAVASCRIPT] Delete in a table the texts containing a "Yy" prefix

New Here ,
May 22, 2021 May 22, 2021

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!

TOPICS
JavaScript
1.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 22, 2021 May 22, 2021

This is not Acrobat JavaScript. It's got a browser. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 22, 2021 May 22, 2021
quote

This is not Acrobat JavaScript. It's got a browser. 


By @Test Screen Name

Do you have a solution in this case?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 22, 2021 May 22, 2021

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 22, 2021 May 22, 2021
quote

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 :

 

reconnaissance_champs.PNG

 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); 
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 22, 2021 May 22, 2021

Photo after executing the function which removes all the fields which do not contain the "Yy" prefix.

execution_fct_supprimer_champs_noYy.PNG

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 22, 2021 May 22, 2021

Acrobat Javascript can't change the text in PDF files. Can't you change the text in the Word document?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 22, 2021 May 22, 2021

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 22, 2021 May 22, 2021

If Acrobat Javascript can't change texts in a PDF document, can it at least hide / hide them?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 22, 2021 May 22, 2021

I forgot to specify I am on Foxit PhantomPDF and I can modify the texts of a PDF on it.


Like this :

screen.PNG


But I would like to automate this action with JavaScript ...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 22, 2021 May 22, 2021

Try a forum for Foxit PhantomPDF.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 22, 2021 May 22, 2021
LATEST

Ok thanks for your answer, I will do that.

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