Written by

Integration Engineer at Cognosante
Question Oliver Wilms · Aug 29, 2024

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

Comments

Julian Matthews · Aug 30, 2024

Have you tried to open the pdf in a text editor like notepad++ to see what it looks like? It might be that the stream is incomplete, or you're writing the base64 to the file output without decoding?

0
Oliver Wilms  Aug 30, 2024 to Luis Angel Pérez Ramos

I confirmed the file is readable and displays correctly.

0
Oliver Wilms  Aug 30, 2024 to Oliver Wilms

The first file I tried to convert to PDF displays at the source system, but it does not look exactly as expected. I copy ther pdf to csp directory and display it there. I also tried a simple html file and it works correctly end-2-end.

0
Oliver Wilms · Aug 30, 2024

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()
 }

0
Oliver Wilms  Aug 30, 2024 to Oliver Wilms

Maybe I have not installed enough for pandoc to work properly in my container. Are there other tools for programmatically creating pdf (from html)?

0
Oliver Wilms  Aug 30, 2024 to Oliver Wilms

I realize that my HTML contains references to css files. I do not yet have the css files where pandoc is running.

0