Word Count in a PDF file

Illustration
Ahmed Alsaadi - 2022-04-12T13:52:56+00:00
Question: Word Count in a PDF file

I have a PDF file "EHP.pdf", I want to count the total number of words in that file? This file has many sections I want to exclude the last section from the calculations. Any suggestions? 

Related Questions

  • Word Count in a PDF file
  • Expert Answer

    Profile picture of Neeta Dsouza Neeta Dsouza answered . 2025-11-20

    Hi Ahmed, you can use extractFileText. You must choose a starter word and a finisher word, this word must be unique. Because, counting will end when Matlab encounters this word. By this way you can count the words between the starter and finisher. 

     

     

    str = extractFileText("EHP.pdf");
    i = strfind(str,"firstWord"); % write here the first word of your pdf
    ii = strfind(str,"lastWord"); % write here the last word of your pdf, that must be distinctive
    start = i(1);
    fin = ii(1);
    extracted = extractBetween(str,start,fin-1)
    uniqueWordNumbers = wordCloudCounts(extracted);
    counter = uniqueWordNumbers(:,2);
    counterArray = table2array(counter);
    totalWords = sum(counterArray);

     


    Not satisfied with the answer ?? ASK NOW

    Get a Free Consultation or a Sample Assignment Review!