SOAP interface

The WSDL definition of the SOAP WebService of HTML2PDF can be found here:

http://online.htmltopdf.de/?WSDL

This WerService exports the CreatePDF and CreatePDF2 methods that are called with these parameters:

$url

The URI string of the website that should be converted to PDF. This string may be up to 4096 characters long. The address has to start with http or https – other protocols are not supported currently.

$license

The license key, if available. Otherwise an empty string or NULL.

$header

If you have a license key, you can define an individual heading text here that is displayed on every page of the PDF. Without a license key a default text with a link to the WebService will be shown there. If you have no license key, you should give an empty string or NULL in this parameter.

$orientation

Set this to „Portrait“ or „Landscape“ to define the page orientation.

$background

Set this to „1“ or „0“ to en- or disable processing background colors and images.

$print

Set this to „1“ or „0“ to en- or disable processing print media CSS.

Return value

The WebService will return the base64 encoded data of the PDF file, if succeeded. On failure the method will return NULL or throw an SoapFault exception.

Coding example C#

At first add a web reference to the HTML2PDF WebService to your project (use the WSDL definition URI as shown above). If you choose the namespace „de.wan24.html2pdf“, you can use the method CreatePDF in your C# code as shown in this example:

using System;
using System.Security.Cryptography;
using System.Text;

namespace wan24
{
    public static class HTML2PDF
    {
        static HTML2PDF()
        {
            License = null;
        }

        public static string License { get; set; }

        public static byte[] CreatePDF(string url)
        {
            return CreatePDF(url, "", "Portrait", true, false);
        }

        public static byte[] CreatePDF(string url, string header, string orientation, bool background, bool print)
        {
            string license = License;
            if (license != null && license != "")
            {
                StringBuilder temp = new StringBuilder();
                foreach (byte b in SHA1.Create().ComputeHash(Encoding.Default.GetBytes(url + license)))
                    temp.Append(String.Format("{0:x2}", b));
                license = temp.ToString();
            }
            using (de.wan24.html2pdf.Html2PdfService service = new de.wan24.html2pdf.Html2PdfService())
            {
                return Convert.FromBase64String(service.CreatePDF2(url, license, header, orientation, (background)?"1":"0", (print)?"1":"0"));
            }
        }
    }
}

The static class HTML2PDF may now be used like this:

            wan24.HTML2PDF.License = "";// Enter the license key here, if available
            // Create the PDF and write it to the file "demo.pdf"
            File.WriteAllBytes("demo.pdf", wan24.HTML2PDF.CreatePDF("http://wan24.de"));