By Chris Malek | 14 February 2012
Create a PDF file in PeopleCode using the Query API
Have you ever wanted to create a PDF file in Application Engine or Peoplecode? Well it turns out it is not too hard. The PDF will be somewhat limited but this method can still be very useful in some situations like:
- You have an application engine that logs items to a table and you want to generate a PDF of the warnings and errors.
- You want to report on the rows inserted into a processing table
- You want a basic PDF output based on some SQL
In the example below, we have a query called “CHG_ERROR_LIST” that is defined in query manager. The query does not have any prompts. However, we still have to pass the
RunToFile method a dummy PromptRecord object as it is a requirement for the query API.
The resulting PDF for this test code will be in
/appl/shared_files/queryToFile.pdf which I can guarantee is not valid for your environment.
function getWritablePath() returns string /* This function should return a writable path in your installation. */ return "/appl/shared_files/"; end-function; Function queryToFile() Local ApiObject &objQry; &objQry = %Session.GetQuery(); If &objQry.open("CHG_ERROR_LIST", True, True) = 0 Then Local string &path; &path = getWritablePath() | "queryTofile.pdf"; If &objQry.RunToFile(&objQry.PROMPTRECORD, &path, %Query_PDF, 0) = 0 Then /* A zero return means success which is counter-intuitive */ End-If; &objQry.CLOSE(); End-If;