Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 10 of 10 total
Thread POST request and PDF result
Mon, Jul 8 2013 8:56 AMPermanent Link

Christian Kaufmann

Is it correct, that I cannot send a TServerRequest and then load the
Response as a PDF document in the browser? If I understand correctly,
this is an XmlHttpRequest restriction.

So I try to use a TPanel and call SubmitForm. But how can I specify,
that the response (= my PDF document) goes to a new browser window?

Or what are other solutions for reporting?

cu Christian
Mon, Jul 8 2013 10:16 AMPermanent Link

Walter Matte

Tactical Business Corporation


I send PDF's back from my server with the following ContentType and HeaderText.

If you look up Content-Disposition - you can change 'attachment' to 'inline' - then the browser should show the PDF.  OF course every Browser is different.....

         Response.ContentType := 'application/pdf';
         Response.HeaderText :=
              Response.HeaderText +
              'Cache-Control: must-revalidate, post-check=0, pre-check=0' + #13#10 +
              'Cache-Control: public' + #13#10 +
              'Content-Description: File Transfer' + #13#10 +
              'Content-Disposition: attachment; filename=Report.pdf' + #13#10;


See also ....
http://stackoverflow.com/questions/1395151/content-dispositionwhat-are-the-differences-between-inline-and-attachment

Walter
Mon, Jul 8 2013 11:09 AMPermanent Link

Christian Kaufmann

The problem is not, what to send back. The problem is how to handle it
in EWB.

I found a solution but I had to change the EWB library. I made a
public property for the FForm variable in TCustomPanel. Then the
following code works:


var
 p : TPanel;
begin              
 p := TPanel.Create(Self);
 p.FormURL := '/services/ModulEntryEwb/Reports/Test.pdf';
 p.Form.target := '_blank';   
 p.SubmitForm;
 p.Free;


However there is still the trade off, that I cannot set Request
Headers for a Html form submit. So once more I need another handling
for username / password on my server (since Header X-EwbUser,
X-EwbPassword is missing).
Of course this can be done, but programming for the web is always full
of workarounds and exceptions.

cu Christian
Mon, Jul 8 2013 11:57 AMPermanent Link

Matthew Jones

You want to look at TPage.

/Matthew Jones/
Mon, Jul 8 2013 2:50 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Christian,

<< Is it correct, that I cannot send a TServerRequest and then load the
Response as a PDF document in the browser? If I understand correctly, this
is an XmlHttpRequest restriction. >>

Well, you can certainly do such a server request and get the response back,
but the problem is that the browser (and EWB) doesn't know what to do with
the text response since you can't natively display or manipulate PDF files
as strings in a browser.

You need to use a TPlugin to display PDF content, which will allow the
browser to know the MIME type of the PDF content and load the appropriate
plugin.

Another option is to skip PDFs and go with straight HTML.  In such a case,
you have a lot more control over the data, can use a server request, and can
put the string response directly into a TPage control using this property:

http://www.elevatesoft.com/manual?action=viewprop&id=ewb1&comp=TPage&prop=DocumentText

Tim Young
Elevate Software
www.elevatesoft.com


Mon, Jul 8 2013 4:49 PMPermanent Link

Christian Kaufmann

>You need to use a TPlugin to display PDF content, which will allow the
>browser to know the MIME type of the PDF content and load the appropriate
>plugin.

Yes this works fine. But I would prefere a new browser window
(target="_blank") and this is not possible now. Ok, I changed unit
WebCtrls and made a public property for TCustomPanel.FForm to set the
target myself.

This works fine except in IE. The server recives multiple requests.
The first one is fine, but the second one has an empty POST stream. I
still have to investigate here.

Maybe I end up with a solution, that I use a TServerRequest and
prepare a temporary PDF file on the webserver. Then I send back the
url to this file and display it as regular link.

cu Christian
Mon, Jul 8 2013 5:11 PMPermanent Link

Walter Matte

Tactical Business Corporation


I just use DOM object....

 window.location.href:= gbURL + '/rpt?Type=PDF&StatId=' + IntToStr(Stat2.Columns['StatId'].AsInteger);

or

 window.open('http://www.domain.ne/rpt?Type=PDF&StatId=1','_blank','',false);


Walter
Mon, Jul 8 2013 5:17 PMPermanent Link

Christian Kaufmann

>I just use DOM object....
>
>  window.location.href:= gbURL + '/rpt?Type=PDF&StatId=' + IntToStr(Stat2.Columns['StatId'].AsInteger);
>
>or
>
>  window.open('http://www.domain.ne/rpt?Type=PDF&StatId=1','_blank','',false);


This creates GET requests on the server. I want POST requests. I made
some more tests and event with a TPage the IE sends a correct POST
request first, but then I have to GET requests with the correct url,
but my POST variables are missing. Very strange, I don't understand
exactly what happens. Firefox and Chrome don't have this problem.

cu Christian
Mon, Jul 8 2013 5:40 PMPermanent Link

Christian Kaufmann

>This works fine except in IE. The server recives multiple requests.
>The first one is fine, but the second one has an empty POST stream. I
>still have to investigate here.

I think, I found the problem. I tried with a .TXT file and there is
one POST request only. So I think, the FoxIt PDF plugin in IE causes
the two additional GET requests with the same URL.
Maybe somebody can confirm that, because this means, PDF as response
to a POST request will always be a problem!!!

So the following way will be the solution for dynamic PDF reports:
>Maybe I end up with a solution, that I use a TServerRequest and
>prepare a temporary PDF file on the webserver. Then I send back the
>url to this file and display it as regular link.


cu Christian
Thu, Jul 11 2013 12:06 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Christian,

<< Maybe I end up with a solution, that I use a TServerRequest and prepare a
temporary PDF file on the webserver. Then I send back the url to this file
and display it as regular link. >>

We have other users using this method with success.

Tim Young
Elevate Software
www.elevatesoft.com
Image