3

I'm trying to output a PDF using server side javascript (ASP). The current method I'm using is:

xfile=Server.MapPath(lib.fso.GetTempName())
xf=lib.fopen(xfile,"wb");
lib.fwrite(xf,this.buffer);
lib.fclose(xf);
outB = Server.CreateObject("ADODB.Stream")
outB.Type = 1
outB.Open()
outB.LoadFromFile (xfile)
Response.BinaryWrite(outB.Read())
outB.Close()
lib.fso.DeleteFile(xfile);

This works, but requires write access on the server. Is there a way to do the same thing without writing to a file?

I havn't been able to figure out how to convert the string this.buffer into a array of byte that I can then write using Response.BinaryWrite without writing to a file first.

2 Answers 2

1

Why not simply use:-

Response.Write(this.buffer)

Assuming the codepage of the response is set correctly (I.e., its the same as in the Locale that the VBScript is running in) then Response.Write should do the same conversion that your StringToMultiByte is doing.

I suspect you've tried this and is hasn't worked. If so I really think you need to look into why that is rather attempt this strange usage of BinaryWrite. Currently your solution is going to kill your server.

Sign up to request clarification or add additional context in comments.

1 Comment

Could you be more clear on "going to kill your server"? I did try the Response.write method, but it created corrupt PDFs. I suspect this is due to how the images are encoded and output as text. I'd bet that Response.write does some sort of encoding which is corrupting the image data as it is written to the output buffer.
0

My solution was to use VBScript.

replace the above code with:

Response.BinaryWrite(StringToMultiByte(this.buffer));

and add this to the end of the file:

<script language="vbscript" runat="server">

function StringToMultiByte(S)
   Dim i, MultiByte
   For i=1 To Len(S)
   MultiByte = MultiByte & ChrB(Asc(Mid(S,i,1)))
   Next
   StringToMultiByte = MultiByte
End function

</script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.