Winnovative Software Logo

 HTML to PDF Converter - Excel Library - ASP.NET Charts - RTF to PDF Converter
 PDF Merge and Split - PDF Security - PDF Viewers - PDF to Text - Images Extractor

 
Skip Navigation Links
Home
ProductsExpand Products
Online DemoExpand Online Demo
Download
Buy NowExpand Buy Now
SupportExpand Support
Contact
 
Dynamically Create PDF Invoices
This demo shows how to dynamically create printable invoices directly from ASP.NET pages. The invoice will contain the customer name, email, phone number and email and the list of invoice items.

From this configuration page you can enter the customer details and the invoice items. When you press the 'Generate Invoice' button, the information you introduced and stored in the current session will be used to fill the invoice template page, which is a regular ASP.NET page. The HTML to PDF Converter will convert the invoice template page to a PDF document or to an image.
Use the 'Add Item to Invoice' button to add invoice items and the click the 'Generate Invoice' button to create the PDF invoice for the added items.
Customer Information
Name:  
Address #1:  
Address #2:  
Phone:  
Email:  
Add Item to Invoice:
Product Code:  
Product Name:  
Product Description:  
Price:  
Quantity:  
     Items currently added:  0 
   Preview report web page
Ivoice items:
 

 C# Code Sample
    /// <summary>
    /// Generate the PDF invoice from the HTML template based on the current session data
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnGenerateInvoice_Click(object sender, EventArgs e)
    {
        if (!Page.IsValid)
            return;

        // save customer info on the session 
        // to make it available in the report page
        SaveCustomerInfo();

        // get the html string for the report
        StringWriter htmlStringWriter = new StringWriter();
        Server.Execute("InvoiceTemplate.aspx", htmlStringWriter);
        string htmlCodeToConvert = htmlStringWriter.GetStringBuilder().ToString();
        htmlStringWriter.Close();

        //initialize the PdfConvert object
        PdfConverter pdfConverter = new PdfConverter();

        // set the license key - required
        pdfConverter.LicenseKey = "R8nYyNnI2MjRxtjI29nG2drG0dHR0Q==";

        pdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4;
        pdfConverter.PdfDocumentOptions.PdfCompressionLevel = PdfCompressionLevel.Normal;
        pdfConverter.PdfDocumentOptions.ShowHeader = false;
        pdfConverter.PdfDocumentOptions.ShowFooter = false;

        // get the base url for string conversion which is the url from where the html code was retrieved
        // the base url is used by the converter to get the full URL of the external CSS and images referenced by relative URLs
        string baseUrl = HttpContext.Current.Request.Url.AbsoluteUri;

        // get the pdf bytes from html string
        byte[] pdfBytes = pdfConverter.GetPdfBytesFromHtmlString(htmlCodeToConvert, baseUrl);

        System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
        response.Clear();
        response.AddHeader("Content-Type", "application/pdf");
        response.AddHeader("Content-Disposition", String.Format("attachment; filename=PdfInvoice.pdf; size={0}", 
                    pdfBytes.Length.ToString()));
        response.BinaryWrite(pdfBytes);
        // Note: it is important to end the response, otherwise the ASP.NET
        // web page will render its content to PDF document stream
        response.End();
    }