IMPORTANT NOTICE:  As of 21 February, anything posted in this community WILL NOT BE MIGRATED to our new community site.   We have pulled all user information and data from this site and are now in an approximately week long process of importing users, roles, and data to our new site.  We are leaving this site open and active so you can post and hopefully get a response until the migration is complete.   Once complete, the URL  that currently takes you to this site will take you to our new site so your bookmarks will work as always.  Please read the information on a New Login Process

Verifying text in PDF documents with Foxit Reader

Author: Ralph Mayr

The output of an application might often be produced as a PDF document. Being able to verify that the contents of such a PDF document are valid and correct is very useful for automated testing.

This blog entry describes how you can easily validate such a PDF, by using the built-in TextExists method of Silk Test in combination with the free PDF Reader Foxit Reader.

Note: The procedure is described based on Silk4J, the Silk Test plug-in for Eclipse, but can also be performed with the other Silk Test clients.

We performed the following actions to validate the text contents of a sample PDF, downloaded from the data sheets Borland website, with Silk Test and the Foxit Reader:

  1. Download and install Foxit Reader from
  2. Make the Foxit Reader the standard program to open PDFs.
  3. In Silk4J, create a new Silk4J project for the Borland website,
  4. Record a simple test case that downloads the sample PDF and opens it in the Foxit Reader.

The test includes a step to convert the PDF to plain text by pressing Ctrl+6. With plain text, the test validates that a specific text is included in the PDF by using the TextExist method.

The following sample code includes the entire recorded script. In this example, we use a simple verification to verify that the PDF contains the string Silk4J:

desktop.<DomLink> find("//BrowserApplication//BrowserWindow//A[@textContents='Resources']").click();
desktop.<DomLink> find("//BrowserApplication//BrowserWindow//A[@textContents='Resource search']").click();
desktop.<DomListBox> find("//BrowserApplication//BrowserWindow//SELECT[@id='p_lt_CMSWebPartZone5*']").select("Datasheet"); desktop.<DomListBox>
find("//BrowserApplication//BrowserWindow//SELECT[@id='p_lt_CMSWebPartZone5*'][2]").select("Automated Testing");
desktop.<DomListBox> find("//BrowserApplication//BrowserWindow//SELECT[@id='p_lt_CMSWebPartZone5*'][3]").select("Silk Test");
desktop.<DomButton> find("//BrowserApplication//BrowserWindow//INPUT[@class='ContentButton']").click();
desktop.<DomLink> find("//BrowserApplication//BrowserWindow//A[@textContents='Read more »'][3]").click();
desktop.<DomLink> find("//BrowserApplication//BrowserWindow//A[@textContents='Read more »']").click();
desktop.<Control> find("/Window[@caption='*Foxit Reader']//Control[@caption='Reader']").typeKeys("<Left Ctrl+6>");
Assert.assertTrue(desktop.<TextField> find("/Window[@caption='*Foxit Reader']//TextField").textExists("Silk4J"));