EVO HTML to PDF Converter

Stamp PDF Documents

EVO PDF Client for .NET Documentation

EVO HTML to PDF Converter is not just a simple HTML to PDF converter, is also a complete library which you can use to edit existing PDF documents. You can create a Document object from an existing PDF document using the DocumentDocument(String) constructor which takes the full path a PDF file as parameter or the DocumentDocument(Byte) constructor which reads the PDF from a memory buffer. There are also variants of these constructors taking an additional parameter which is the password to open the PDF document: DocumentDocument(String, String) and DocumentDocument(Byte, String).

Each type of constructor has also a variant which accepts the HTML to PDF Server IP address and port as parameters like DocumentDocument(String, UInt32, String) and also a variant which accepts the HTTP URL of the HTML to PDF Server as parameter like DocumentDocument(Boolean, String, String)

A common example of editing an existing PDF document is you to add watermarks and stamps to that PDF document. The watermarks and stamps are implemented using EvoPdf.HtmlToPdfClientTemplate objects which are repeated in each page of the generated PDF document. In a template you can add any PDF element that you can normally add in a PDF page, including HtmlToPdfElement objects or HtmlToPdfVariableElement.

Code Sample - Stamp PDF Documents

C#
protected void stampPdf()
{
    // Get the server IP and port
    String serverIP = textBoxServerIP.Text;
    uint serverPort = uint.Parse(textBoxServerPort.Text);

    // Load the PDF document to stamp
    string pdfFileToStampPath = Server.MapPath("~/DemoAppFiles/Input/PDF_Files/PDF_Document.pdf");
    Document pdfDocument = null;
    if (radioButtonUseTcpService.Checked)
        pdfDocument = new Document(serverIP, serverPort, pdfFileToStampPath);
    else
        pdfDocument = new Document(true, textBoxWebServiceUrl.Text, pdfFileToStampPath);

    // 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 stamp width and height
    float stampWidth = float.Parse(stampWidthTextBox.Text);
    float stampHeight = float.Parse(stampHeightTextBox.Text);

    // Center the stamp at the top of PDF page
    float stampXLocation = (pdfDocument.GetPage(0).PageSize.Width - stampWidth) / 2;
    float stampYLocation = 0;

    // Create the stamp template to be repeated in each PDF page
    Template stampTemplate = pdfDocument.AddTemplate(stampXLocation, stampYLocation, stampWidth, stampHeight);

    // Create the HTML element to add in stamp template
    HtmlToPdfElement stampHtmlElement = new HtmlToPdfElement(htmlStringTextBox.Text, baseUrlTextBox.Text);

    // Set the HTML viewer width for the HTML added in stamp
    stampHtmlElement.HtmlViewerWidth = 600;
    // Fit the HTML content in stamp template
    stampHtmlElement.FitWidth = true;
    stampHtmlElement.FitHeight = true;

    // Add HTML to stamp template
    stampTemplate.AddElement(stampHtmlElement);

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