Delivering a PDF to a Browser


Method 1: Anchor Tags


The <a> tag defines a hyperlink, which is used to link from one page to another.


The most important attribute of the <a> element is the href attribute, which indicates the link's destination.










hrefURLSpecifies the URL of the page the link goes to

Example: <a href=”test.pdf” target=”_blank”>PDF Link</a>


 


The target attribute is used to specify where the linked document will open.










target_blank
_parent
_self
_top
Specifies where to open the linked document

 


The text between the tags will be the actual link that is clicked to open the document.


Example: <a href=”test.pdf” target=”_blank”>PDF Link</a>


href=”test.pdf” - This tells it that the target document to open is the "test.pdf"


target=”_blank” - This tells it to open the PDF in a new blank page.


PDF Link - this is the text that will show up as a hyperlink on the page.


 


For more information on how to use an Anchor tag <a>, please refer to the link below...


https://www.w3schools.com/tags/tag_a.asp


 


 


 


Method 2: Response.AddHeader


The ASP Response object is used to send output to the user from the server.


Example:


Current.Response.AddHeader("Content-Type","application/pdf")
Current.Response.AddHeader("Content-Disposition", "inline; filename=" + documentTitle + ".pdf")
Current.Response.BinaryWrite(PDFByteStream)
Current.Response.End()




  • AddHeader method adds a new HTTP header and a value to the HTTP response.


  • BinaryWrite Writes data directly to the output without any character conversion.


  • End Stops processing a script, and returns the current result.


The important thing to note with this method is that the PDF must be byte[]. While this is outside the functionality of most of the ActivePDF Products (Toolkit being the exception). It is very simple to read a file in as a byte stream.


C# Example: ReadAllBytes


byte[] PDFByteStream = System.IO.File.ReadAllBytes(pathToPDF);


 


For more information on using the Response object, please refer to the link below...


https://www.w3schools.com/asp/asp_ref_response.asp