'Need to compare contents of word template & actual PDF

I have 2 files (word & pdf) and need to compare them. word doc will be template which defines how pdf should be generated. Below are the samples.

Word doc:

    <firstname>,<LastName>
    <ID>,<organization>
    <salary>,<place>
    
    Dear <firstname>,
    you are working in the department of <organization> and we are really honored to have you here. Expecting many more successful years of service from you.
    Thanks,

Actual PDF:

    John, Kennedy
    234,google
    USD1245,CA
    
    Dear John,
    you are working in the department of google and we are really honored to have you here. Expecting many more successful years of service from you.
    Thanks,

Can someone help with the comparison logic to validate both the static and dynamic content are getting generated as expected?? we are using TestComplete with JavaScript for the automation.



Solution 1:[1]

If you know what is in the template, you could start with some regex splitting first few lines where are all variables. Then read the template, replace every variable with values got from pdf beggining and if the replaced text matches the text in pdf, then you have pdf built from template.

Regex splitting example: read word file, split every line, get the first 3 lines, split them with ",", and set the vars to coresponding indexes. As I said, this works only if you know the content of the template

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Atzuki