Outputting a PDF document from a script page is a straightforward process. The following code example -  

<script runat="server">

var myfile = new File("mydoc.pdf");

response.contentType="application/pdf";

response.setBinaryMode();

write(myfile);

</script>

 

performs the following steps:

  1. Creates a file object which refers to a PDF file.

  2. Sets the content type to the mime type for PDF.

  3. Switches the response into binary mode.

  4. Writes the PDF document file to the requesting client browser. Note that the file object is written using the write() function call and not writeln() function call; to avoid the additional bytes.

Comment on this topic

Topic ID: 150082