Developer Guide
PDF Response

    This response type is very similar to the File response type. It allows you to generate dynamic PDF files and allow users to download the PDF file.

    Note: This feature converts HTML or ActivePage into a PDF. It is important to keep in mind to use absolute paths for referenced resources such as CSS or Images in order for the images to show correctly in the PDF.

    If you would like to render your current ActivePage to PDF, you need to write your action method as below:

    public ActionResponse Index()
    {
         List<Account> accounts = Database.Query<Account>(acc => !string.IsNullOrEmpty(acc.Type)).ToList();
         return Pdf(accounts, "account_list.pdf");
    }
     

    If you would like to prepare your PDF content within the action method itself, you can still generate PDF using this formatting:

    public ActionResponse Index()
    {
         string myPDFContent = "Hello, world!";
         return Pdf(myPDFContent, "hello_world.pdf");
    }
     

    Using the following overloads, you can better control the way in which the PDF files are generated.

    • Pdf(object model, [string filename], [PdfOptions exportOptions], [bool inline=false])
    • Pdf(string content, [string filename], [PdfOptions exportOptions], [bool inline=false])
       
    Using PDF Options allows you to control the PDF page size, compression level, page orientation and page margins. All parameters presented in brackets are optional.