One thing to be *absolutely* sure of is that you do not have ANY
output before the PDF download starts.
If you have Apache2 with mod_header loaded, there is a FilesMatch
directive to always force a download for a PDF
<FilesMatch "\.(?i:pdf)$">
ForceType application/octet-stream
Header set Content-Disposition attachment
</FilesMatch>
On a side note, you do not need AJAX for this feature to feed the user
a PDF file for download just set the form action to empty (same page)
and it should leave the page/browser right where it is with the form
still filled out, unless you are trying to feed a PDF to a div... you
aren't are you?
by the by which PDF library did you use to generate with?
unless i am missing something you won't be able to feed to the same
browser instance two different things - application/pdf and text/html
without using a response handler to parse some kind of response from
the server (prolly json would be easiest) with a textual response and
then a hidden iframe that you can redirect to a link provided in the
json.
>
> Brian,
>
> Thank you for the Apache directive! Nice tip, although unfortunately I
> am in an environment where I can't rely on Apache directives, since I
> don't control that. Yes, I don't need AJAX to feed a file to the user,
> but as I mentioned above, I would love to have it in case something
> fails - in that case I can let the user know that something went
> wrong. Perhaps there's a way to do that which I can't see?..
see above
>
> We are using FPDF (http://www.fpdf.org/), which is free and suits our
> needs pretty well (generating two types of rather simple reports, as
> well as an invoice). Anything better out there?
>
> Best regards,
> Max
yes, something that is much more up to date (and actually still in
development) which is based on FPDF and is free
http://www.tecnick.com/public/code/cp_dpage.php?aiocp_dp=tcpdf
It's been my experience that if you leave the action blank, you
submit the page to itself. What that page does in response to a POST
or GET is entirely up to that page. So, if you had "wired" your page
to play back the submitted variables (or if you were using a
framework that did this sort of thing automagically) then you would
see the form completed, as if nothing had changed. But if you did not
have such a thing going on in the background, you would see an empty
form. The browser would not re-fill (excepting any sort of auto-fill
behavior) the fields.
Walter