Operating System - OpenVMS
cancel
Showing results for 
Search instead for 
Did you mean: 

Apache Content-Type for PDF

 
SOLVED
Go to solution
Robert Atkinson
Respected Contributor

Apache Content-Type for PDF

Hi all.

I'm trying to output a PDF file through Apache using the DCL code below, but the file is just displayed as text to the browser (MSIE) rather than being launched in Acrobat.

Any ideas how I can make this work?

Rob.

$ !
$ WS F$FAO("!AS!/!/","Content-type: application/pdf")
$ WS ""
$ !
$ TYPE WEBREPORT$STORE:ALPD_20040729_3F9B.PDF;1
$ !
8 REPLIES
Ian Miller.
Honored Contributor

Re: Apache Content-Type for PDF

do links to pdf files on other web sites work i.e. is IE properly setup to handle this content type?
____________________
Purely Personal Opinion
Robert Atkinson
Respected Contributor

Re: Apache Content-Type for PDF

Yes.

The code currently loads the file as http://server/webreports/store/filename.pdf, but I want to make the system more secure by hiding the filename and accessing it using some kind of session generated alias.

Rob.
Sebastian Bazley
Regular Advisor

Re: Apache Content-Type for PDF

MSIE tends to ignore the content-type, and just uses the file extension to determine how to treat it.

Try loading the URL in a different browser to see if this is the case.

If so, then you will need to include the .PDF file type to keep MSIE happy.

You may be able to get away with adding a query string to the URL, e.g. something like

http://server/whatever.ext?type=.pdf
David Jones_21
Trusted Contributor

Re: Apache Content-Type for PDF

Aside from IE issues with content type, PDF is a binary format so using TYPE to include it in your script's output is likely to transfer the data incorrectly. TYPE will open the file with RMS, which will try to parse out 'records' the data that may not be there.
I'm looking for marbles all day long.
Willem Grooters
Honored Contributor

Re: Apache Content-Type for PDF

PDF (Portable Document Format) is a way to code the document into an ASCII format that a reader can interpret so it can transform the ASCII file into a presentable display. Readers are platform dependent. There's one for windows, different Unix flavors and one for VMS (but I'm uncertain about the status of that one. Way behind, I guess). You can compare this to the PostScript (PS) format for printers: if a printer contains the interpreter software, it will print the document as intended, otherwise it will just be the ASCII text - quite meaningless.

TYPE will look at the file as an ASCII file and will not do any interpretation so you will see the text as it is. Try typing a PS file and you'll see the same type of output.
To read the file on VMS, you need the reader.
To read it via Apache, I think what you need to do is defining a mime.type line in apache$root:[conf]httpd.conf for PDF, something like:

AddType application/x-acroread .pdf

but I'm not sure what to specify in this case.

Willem
Willem Grooters
OpenVMS Developer & System Manager
Karl Rohwedder
Honored Contributor
Solution

Re: Apache Content-Type for PDF

In the releasenotes is some information about transfering binary data, CSWS include a special APACHE$BIN_DCL for this purpose.

regards Kalle
Robert Atkinson
Respected Contributor

Re: Apache Content-Type for PDF

Karl was on the right line with the VMS Apache utilities.

The final solution looks something like this :-

$ APACHE$DCL_BIN := $ APACHE$ROOT:[000000]APACHE$DCL_BIN.EXE_'F$GETSYI("ARCH_NAME")'
$ APACHE$DCL_ENV := $ APACHE$ROOT:[000000]APACHE$DCL_ENV.EXE_'F$GETSYI("ARCH_NAME")'
$ APACHE$DCL_RUN := $ APACHE$ROOT:[000000]APACHE$DCL_RUN.EXE_'F$GETSYI("ARCH_NAME")'
$ APACHE$FLIP_CCL:= $ APACHE$ROOT:[000000]APACHE$FLIP_CCL.EXE_'F$GETSYI("ARCH_NAME")'
$ !
$! APACHE$ROOT:[CGI-BIN]GETPDF.COM
$ REPORT = "WEBREPORT$STORE:AWPFWDRP3_20050823_1686.PDF"
$ APACHE$FLIP_CCL
$ WRITE SYS$OUTPUT F$FAO("!AS!/!/","Content-Type: application/pdf")
$ APACHE$DCL_BIN 'REPORT'
$!

FLIP_CCL changes the output (SYS$OUTPUT) so that CRLF isn't sent, and DCL_BIN enables you to output binary files in chunks.

All this is of course, very badly documented by Apache!

Rob.
Bojan Nemec
Honored Contributor

Re: Apache Content-Type for PDF

Rob,


I did some testing. As I have no Apache installed I just write a simple TCPIP service:

$ open/read/write x sys$net
$ write x F$FAO("!AS!/","HTTP/1.0 200 OK")
$ write x F$FAO("!AS!/","Content-type: application/pdf")
$ write x F$FAO("!/")
$ define sys$output x/nolog
$ type sys$login:h.pdf
$ close x

First tests was not succesful. Acrobat complains on the file.
I save the file on the disk and see that the CR/LF pairs were replaced to one CR. So I did SET FILE/ATTR=(RFM=FIX,LRL=512,MRS=512) on the pdf file. Now works all fine.

Bojan