PdfStorageAdapterGetDocumentAsPdf Method (String) |
Namespace: RadPdf.Integration
Exception | Condition |
---|---|
InvalidOperationException | The current instance has already been disposed. |
RadPdfDocumentException | The document was not found in storage. |
If document is not found or inaccessible, an exception will be thrown.
This example (DocumentDownload.ashx) demonstrates how to use the GetDocumentAsPdf() method to create a download page for PDF documents stored in RAD PDF without a PdfWebControl instance.
This example assumes that the query string is a RAD PDF document key.
<%@ WebHandler Language="C#" Class="DocumentDownload" %> using System; using System.Web; using RadPdf.Data.Document; using RadPdf.Integration; public class DocumentDownload : IHttpHandler { public void ProcessRequest(HttpContext context) { // Get query string (which we presume to be the document key for this example) string queryString = context.Request.Url.Query; // Trim leading ? from querystring queryString = queryString.Substring(1); // Declare variables string fileName; byte[] pdfData; // Create storage adapter instance using(PdfStorageAdapter adapter = new PdfStorageAdapter()) { // Get document filename fileName = adapter.GetDocumentProperties(queryString).DocumentFileName; // Get bytes from storage for the document pdfData = adapter.GetDocumentAsPdf(queryString); } // Add Content-Type context.Response.ContentType = "application/pdf"; // Add header to indicate download (the filename parameter can not contain spaces in many browsers) context.Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName.Replace(' ', '_') + ".pdf"); // Output pdf to response context.Response.BinaryWrite(pdfData); // Set response status code context.Response.StatusCode = 200; } public bool IsReusable { get { return true; } } }