lua script serving pdf files

Use this Forum to post your “How to …” questions about your use of aXes. This is not a technical support forum. Both the aXes Support Team at LANSA and other aXes customers may answer your questions. LANSA cannot guarantee the accuracy of any information posted by customers.

Moderator: jeanmichel

Post Reply
jaimosky
Posts: 15
Joined: 30 May 2017, 16:48

lua script serving pdf files

Post by jaimosky » 20 Feb 2018, 17:41

Hi,

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
The problem is that we do not get the header Content-Disposition, so the webbrowser receives the stream but doesn´t know what to do with it. Well, if you associate the .lua with pdf viewer then it works, but we would like to do it without this association.

Do you think is this possible?

Post Reply