Click or drag to resize

PdfStorageAdapterGetDocumentAsPdf Method (String)

Retrieve a document previously loaded into a PdfWebControl instance with all saved modifications, as a PDF.

Namespace:  RadPdf.Integration
Assembly:  RadPdf (in RadPdf.dll) Version: 3.44.0.0 (3.44.0.0)
Syntax
public byte[] GetDocumentAsPdf(
	string documentKey
)

Parameters

documentKey
Type: SystemString
DocumentKey as a string.

Return Value

Type: Byte
The document in PDF format for the documentKey parameter.
Exceptions
ExceptionCondition
InvalidOperationExceptionThe current instance has already been disposed.
RadPdfDocumentExceptionThe document was not found in storage.
Remarks

If document is not found or inaccessible, an exception will be thrown.

Examples

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.

C#
<%@ 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;
        }
    }
}
See Also