EVO HTML to PDF Converter

Create PDF Documents

EVO PDF Client for .NET Documentation

EVO HTML to PDF Converter allows you to create empty PDF documents to which you can add various types of elements: HTML, text, images, graphics. You can save the created PDF document to a file, a stream or in a memory buffer. A PDF document is represented in API by a EvoPdf.HtmlToPdfClientDocument object.

When you create a PDF document you can choose the PDF Standard and the Color Space in Document object constructor. You can also choose the PDF page size, orientation and margins when you add a page to PDF document using the DocumentAddPage(PdfPageSize, PdfMargins, PdfPageOrientation) method.

Code Sample - Create PDF Documents

C#
protected void createPdf()
{
    // Get the PDF Standard
    // By default the Full PDF standard is used
    PdfStandardSubset pdfStandard = PdfStandardSubset.Full;
    if (pdfARadioButton.Checked)
        pdfStandard = PdfStandardSubset.Pdf_A_1b;
    else if (pdfXRadioButton.Checked)
        pdfStandard = PdfStandardSubset.Pdf_X_1a;

    // Get the Color Space
    // By default the RGB color space is used
    ColorSpace pdfColorSpace = ColorSpace.RGB;
    if (grayScaleRadioButton.Checked)
        pdfColorSpace = ColorSpace.Gray;
    else if (cmykRadioButton.Checked)
        pdfColorSpace = ColorSpace.CMYK;

    // Create the PDF document
    Document pdfDocument = null;

    // Get the server IP and port
    String serverIP = textBoxServerIP.Text;
    uint serverPort = uint.Parse(textBoxServerPort.Text);

    if (pdfStandard == PdfStandardSubset.Full && pdfColorSpace == ColorSpace.RGB)
    {
        // Create a PDF document with default standard and color space
        if (radioButtonUseTcpService.Checked)
            pdfDocument = new Document(serverIP, serverPort);
        else
            pdfDocument = new Document(true, textBoxWebServiceUrl.Text);
    }
    else
    {
        // Create a PDF document with the selected standard and color space
        if (radioButtonUseTcpService.Checked)
            pdfDocument = new Document(serverIP, serverPort, pdfStandard, pdfColorSpace);
        else
            pdfDocument = new Document(true, textBoxWebServiceUrl.Text, pdfStandard, pdfColorSpace);
    }

    // Set optional service password
    if (textBoxServicePassword.Text.Length > 0)
        pdfDocument.ServicePassword = textBoxServicePassword.Text;

    // Set license key received after purchase to use the converter in licensed mode
    // Leave it not set to use the converter in demo mode
    pdfDocument.LicenseKey = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c=";

    // Get the selected PDF page size
    PdfPageSize pdfPageSize = SelectedPdfPageSize();

    // Get the selected PDF page orientation
    PdfPageOrientation pdfPageOrientation = SelectedPdfPageOrientation();

    // Get the PDF page margins
    PdfMargins pdfPageMargins = new PdfMargins(float.Parse(leftMarginTextBox.Text), float.Parse(rightMarginTextBox.Text),
            float.Parse(topMarginTextBox.Text), float.Parse(bottomMarginTextBox.Text));

    // Create a PDF page in PDF document
    PdfPage firstPdfPage = pdfDocument.AddPage(pdfPageSize, pdfPageMargins, pdfPageOrientation);

    // The URL of the HTML page to convert to PDF
    string urlToConvert = "http://www.evopdf.com";

    // Create the HTML to PDF element
    HtmlToPdfElement htmlToPdfElement = new HtmlToPdfElement(urlToConvert);

    // Optionally set a delay before conversion to allow asynchonous scripts to finish
    htmlToPdfElement.ConversionDelay = 2;

    // Add the HTML to PDF element to PDF document
    firstPdfPage.AddElement(htmlToPdfElement);

    // Save the PDF document in a memory buffer
    byte[] outPdfBuffer = pdfDocument.Save();
}