Web Connection
Print PDF to screen XFRX
Gravatar is a globally recognized avatar based on your email address. Print PDF to screen XFRX
  mhatcher2
  All
  Jan 17, 2017 @ 04:39am

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)

Gravatar is a globally recognized avatar based on your email address. re: Print PDF to screen XFRX
  Harvey Mushman
  mhatcher2
  Jan 17, 2017 @ 08:41am

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?

Gravatar is a globally recognized avatar based on your email address. re: Print PDF to screen XFRX
  Rick Strahl
  mhatcher2
  Jan 19, 2017 @ 12:40am

@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 ---

Gravatar is a globally recognized avatar based on your email address. re: Print PDF to screen XFRX
  mhatcher2
  Rick Strahl
  Jan 19, 2017 @ 07:35am

Thank you so much guys for your help! Worked like a charm (both methods)!

And to answer your question Harvey, I meant version 6 of the new framework. I'm using the latest version of XFRX (16.1.4).

Mark

© 1996-2024