The following script shows how you can call the FOP server from a
Delphi program:
uses ......
IdHTTP;
...
var
lHTTP: TIdHTTP;
response:TMemoryStream;
source: TMemoryStream;
xml:AnsiString;
begin
// input xml data
xml:='<?xml version="1.0" encoding="iso-8859-1"?> <departments><department><departmentName>R&D</departmentName> <person> <name>John Schmidt</name>
';
xml:=xml +'<address>Red street 3</address> <status>A</status> </person> <person> <name>Paul Bones</name> <address>White street 5</address> <status>A</status>
';
xml:=xml +'</person> <person> <name>Mark Mayer</name> <address>Blue street 5</address> <status>A</status> </person> <person> <name>Janet Black</name>
';
xml:=xml +'<address>Black street 8</address> <status>I</status> </person></department><department> <departmentName>Sales</departmentName> <person>
';
xml:=xml +'<name>Juan Gomez</name> <address>Green street 3</address> <status>A</status> </person> <person> <name>Juliet Bones</name> <address>White street 5</address>
';
xml:=xml +' <status>A</status> </person></department></departments>';
lHTTP := TIdHTTP.Create(nil);
response:= TMemoryStream.Create;
source:= TMemoryStream.Create;
// put xml string into a
Stream
source.WriteBuffer(Pointer(xml)^, Length(xml));
// call server
lHTTP.Post('http://localhost:8087/J4LFOPServer/servlet?TEMPLATE=departmentEmployees.fo', source,response);
// save to PDF file
response.SaveToFile('output.pdf');
source.free;
response.free;
lHHTP.free;
end;
|