I am trying to print a PDF document to the screen using XFRX in version 6. It appears that wwHTTPHeader has been replaced with wwHTTP yet some of the functions, like setprotocol() don’t exist anymore. Can someone please help me fill in the blanks?
OPDF=Createobject("wwXFRX")
OPDF.cPrinterDriver = "Apple Color LW 12/660 PS"
LCPDF = OPDF.PRINTREPORTTOSTRING("openorders.frx")
// LOHEADER = Createobject("wwHTTPHeader")
LOHEADER = CREATEOBJECT("wwHTTP")
// LOHEADER.SETPROTOCOL()
// LOHEADER.SETCONTENTTYPE("application/pdf")
LOHEADER.cContentType = "application/pdf"
LOHEADER.AddHeader("Content-Length",Transform(Len(LCPDF)))
LOHEADER.AddHeader("Accept-Ranges","bytes")
// Response.CONTENTTYPEHEADER(LOHEADER)
Response.Write(LCPDF)
Having a PDF open automaticlly in the prowser from a server response is very tricky at best. Not all browsers respond the same to application/pdf in the header. On a smartPhone, I've seen a nasty message popup telling my user they need to down the app. On the desktop, I've seen it just die.
The preferred way is to place the generated PDF file in a folder that is accessable to the client over the web. Then send the client browser the URL to the file. In all of my applications I open the PDF in a new browser window so when the user is done with looking at the document and they close the window, they fall back into my app.
I think what I'm describing is the recomended method described in West-Wind documentation.
Only question, which is Version 6 in your question, Web Connection or XFRX?
@mhatcher,
The code you're using is pretty old and can be much simpler.
Your code can be distilled down to:
OPDF=Createobject("wwXFRX")
OPDF.cPrinterDriver = "Apple Color LW 12/660 PS"
LCPDF = OPDF.PRINTREPORTTOSTRING("openorders.frx")
Response.ContentType = "application/pdf"
Response.Write(lcPdf)
You never need to specify the content-length because Web Connection appends that.
As Harvey points out, there are some issues with PDF files and how they are opened differently in different browsers, but as long as you are using a reasonably recent browser you can be pretty sure that the file will either open in the browser or download as a file.
If you want to be really sure it works is write the PDF to a file, and then create a link to the file like <a href="MyPdf.pdf">Pdf Report</a>
.
+++ Rick ---