Question
· Aug 29

Create PDF and transfer it via REST

Hello, I want to create PDF from HTML source. I found pandoc. I installed pandoc on IRIS container image. I created Interoperability production. I have setup REST service to receive HTML file in request body. I call pandoc command pandoc -o output.pdf input.html  from a BPL process. I copy output.pdf file stream into response body. I save the response at the source. I get a file named output.pdf but it does not load in Acrobat. I suspect I am doing something wrong with headers (accept-encoding?) or maybe do I need to base64 encode the pdf file to transfer it via REST?

Product version: IRIS 2022.2
Discussion (7)2
Log in or sign up to continue

I have seen files transferred inside JSON and I want to try it here. Before (now) I have this code to generate response object:

Set context.Response = ""
 If 1=request.%IsA("EnsLib.HTTP.GenericMessage") {
   If (context.StatusLine = "") {
      Set context.StatusLine = "HTTP/1.1 200 OK"
   }
   If (##class(%File).Exists(context.Outputfile)) {
     Set tStream = ##class(%Stream.FileBinary).%New()
     Set tSC = tStream.LinkToFile(context.Outputfile)
     If $$$ISERR(tSC) Do ##class(Oliver.Util).DebugStatus(tSC)
   }

   //Set tSC = tmp.%Save()
   Set context.Response=##class(EnsLib.HTTP.GenericMessage).%New($Get(tStream),,request.HTTPHeaders)
   Do context.Response.HTTPHeaders.SetAt("application/pdf","Content-Type")
   Do context.Response.HTTPHeaders.SetAt(context.StatusLine,"StatusLine")
   Set tSC = context.Response.%Save()
 }