Sending a PDF to Browser
[1/10] from: reboler:bol at: 14-Sep-2003 19:10
Hi Folks!,
Does anybody know how to send a PDF to browser. I tried this below, but it
doesn't work.
print "Content-Type: application/pdf; filename=file.pdf"
print "Content-Transfer-Encoding: base64"
print "Content-disposition: attachment; filename=file.pdf"
print ""
print read/binary %file.pdf
Any tips?
Thanks in advance,
--DJ
[2/10] from: andrew::martin::colenso::school::nz at: 15-Sep-2003 10:24
DJ wrote:
> print read/binary %file.pdf
That's wrong. You have to send the file contents as binary. Some thing
like this:
MIME: make object! [
Extension_MIME: load %"Extension MIME.txt"
Type?: func [File [file!]] [
select Extension_MIME Extension? File
]
Data: function [File [file!]] [Data] [
Data: read/binary File
print [
"Content-Type:" any [
Type? File
'application/octet-stream
]
newline
]
write-io system/ports/output Data length? Data
Data: none
quit
]
]
MIME/Data File
If you'd like a copy of my %"Extension MIME.txt", email me directly at:
andrew.martin at colenso.school.nz
Andrew J Martin
Attendance Officer &
Information Systems Trouble Shooter
Colenso High School
Arnold Street, Napier.
Tel: 64-6-8310180 ext 826
Fax: 64-6-8336759
http://colenso.net/scripts/Wiki.r?AJM
http://www.colenso.school.nz/
DISCLAIMER: Colenso High School and its Board of Trustees is not responsible (or legally
liable) for materials distributed to or acquired from user e-mail accounts. You can report
any
misuse of an e-mail account to our ICT Manager and the complaint will be investigated.
(Misuse can come in many forms, but can be viewed as any material sent/received that
indicate or suggest pornography, unethical or illegal solicitation, racism, sexism, inappropriate
language and/or other issues described in our Acceptable Use Policy.)
All outgoing messages are certified virus-free by McAfee GroupShield Exchange 5.10.285.0
Phone: +64 6 843 5095 or Fax: +64 6 833 6759 or E-mail: [postmaster--colenso--school--nz]
[3/10] from: reboler:bol at: 14-Sep-2003 20:33
Hi Andrew,
Just to know, how is the complete header that I have to send back to the
server?. Because it's giving an error in my Apache server.. Should I have to
change anything in http.conf, mime.types?
Thanks for your attention.
--DJ
[4/10] from: andrew:martin:colenso:school at: 15-Sep-2003 11:42
DJ wrote:
> Should I have to change anything in http.conf, mime.types?
I don't think so. I've been running this script on Microsoft's IIS
webserver and Imatix's Xitami web servers.
> Because it's giving an error in my Apache server.
Can you give an example, please? Maybe there's something else wrong?
Andrew J Martin
Attendance Officer &
Information Systems Trouble Shooter
Colenso High School
Arnold Street, Napier.
Tel: 64-6-8310180 ext 826
Fax: 64-6-8336759
http://colenso.net/scripts/Wiki.r?AJM
http://www.colenso.school.nz/
DISCLAIMER: Colenso High School and its Board of Trustees is not responsible (or legally
liable) for materials distributed to or acquired from user e-mail accounts. You can report
any
misuse of an e-mail account to our ICT Manager and the complaint will be investigated.
(Misuse can come in many forms, but can be viewed as any material sent/received that
indicate or suggest pornography, unethical or illegal solicitation, racism, sexism, inappropriate
language and/or other issues described in our Acceptable Use Policy.)
All outgoing messages are certified virus-free by McAfee GroupShield Exchange 5.10.285.0
Phone: +64 6 843 5095 or Fax: +64 6 833 6759 or E-mail: [postmaster--colenso--school--nz]
[5/10] from: reboler:bol at: 14-Sep-2003 20:48
I received this error in the apache logfile..:
[Sun Sep 14 20:27:56 2003] [error] [client 127.0.0.1] Premature end of
script headers: f:/apache/cgi-bin/browser.r
Because the browser asks to 'open, 'save, but saves with the program name.
Is there any way to save with a name that I give ?
Thanks.
--DJ
[6/10] from: andrew:martin:colenso:school at: 15-Sep-2003 12:11
DJ wrote:
> Because the browser asks to 'open, 'save, but saves with the program
name.
> Is there any way to save with a name that I give ?
If you're not using MS Internet Explorer (MSIE) browsers, you can
specify a name in the headers, using the Content-Disposition header,
like this:
print rejoin [
"Content-Disposition: attachment; "
{filename="} form last split-path File #"^""
]
But if you're using MSIE, you've got a problem as MS doesn't understand
Content-Disposition
as per specifications. Instead, MSIE uses the
first file name in the URL to name the file! There's some work arounds
that can be done to overcome this, such as renaming one's CGI to be the
same as a directory, (but I haven't managed to make this work yet).
> [Sun Sep 14 20:27:56 2003] [error] [client 127.0.0.1] Premature end of
> script headers: f:/apache/cgi-bin/browser.r
Maybe no blank line? Or perhaps too many?
Andrew J Martin
Attendance Officer &
Information Systems Trouble Shooter
Colenso High School
Arnold Street, Napier.
Tel: 64-6-8310180 ext 826
Fax: 64-6-8336759
http://colenso.net/scripts/Wiki.r?AJM
http://www.colenso.school.nz/
DISCLAIMER: Colenso High School and its Board of Trustees is not responsible (or legally
liable) for materials distributed to or acquired from user e-mail accounts. You can report
any
misuse of an e-mail account to our ICT Manager and the complaint will be investigated.
(Misuse can come in many forms, but can be viewed as any material sent/received that
indicate or suggest pornography, unethical or illegal solicitation, racism, sexism, inappropriate
language and/or other issues described in our Acceptable Use Policy.)
All outgoing messages are certified virus-free by McAfee GroupShield Exchange 5.10.285.0
Phone: +64 6 843 5095 or Fax: +64 6 833 6759 or E-mail: [postmaster--colenso--school--nz]
[7/10] from: warp:reboot:ch at: 15-Sep-2003 3:27
Hello DJ,
I'm using this function successfully with apache:
givepdf: func [name x /local s][
either file? x [
x: join home_local x
s: second third info? x
x: read x
][
s: length? x
]
m-print-page rejoin ["Cache-control: private" newline
"Content-Type: application/pdf" newline
{Content-Disposition: attachment; filename=} name newline
{Content-Length: } s newline
newline
x
]
m-quit
]
hope that helps 8)
Will Arp
[warp--reboot--ch]
[8/10] from: reboler:bol at: 15-Sep-2003 1:06
Thank you Andrew.. It really worked fine.. And with a name and application
as pdf..
[9/10] from: antonr:iinet:au at: 15-Sep-2003 21:06
So it worked fine on MSIE ?
What version?
Anton.
[10/10] from: reboler:bol at: 15-Sep-2003 10:28
Hi Anton,
It works without problems in MSIE 6.0./ Mozilla .
It doesn't work in MSIE 4.0, 5.0.
MSIE 5.5 just with the service pack 2.
Best Regards,
--DJ