We want to develop so kind of script in lua that would serve pdfs from the IBM i.
The way to use it is:
In the aXes mask we placed a push button and in onclick event we call a program in the IBM that prepares a hash and at the end of the onclick event we call a lua script with this hash.
The lua script looks something like this
Here is the code that we are testing
Code: Select all
function trim (s)
return (string.gsub(s, "^%s*(.-)%s*$", "%1"));
end
local querystring = agi.QUERY_STRING
local URLnf = "<html><head><script type='text/javascript'>window.location = '/pdfnf.html'</script></html>";
if string.find(querystring,"IK") == nil then
reply("Content-type: text/html\n\n");
reply(URLnf);
else
local QSIK = "IK=";
local IK = string.gsub(querystring,QSIK,"");
local pgminterface = os400.pgm
local parmDefinitions = { };
local parmValues = { };
parmdefinition = pgminterface.char400(255);
table.insert(parmDefinitions,parmdefinition);
table.insert(parmValues,IK);
parmdefinition = pgminterface.char400(100);
table.insert(parmDefinitions,parmdefinition);
table.insert(parmValues," ");
retcode, err = pgminterface.call("PRODLIB/PGM00345", parmDefinitions, parmValues);
if string.find(querystring,"IK") ~= nil then
local path2 = string.lower(trim(parmValues[2]))
local ending = ".pdf"
if string.find(path2,ending) ~= nil then
local inp = io.open(path2, "rb");
local data = inp:read("*all");
reply("Content-type:application/pdf\nContent-Disposition: inline; filename=\"download.pdf\"\n\n");
reply(data);
else
reply("Content-type: text/html\n\n");
reply(URLnf);
end
else
reply("Content-type: text/html\n\n");
reply(URLnf);
end
end
Do you think is this possible?