Convert HTML to PDF

Use this site to convert HTML to a PDF. You can convert from a web address, raw HTML or from a file. Alternatively use our API to convert a file remotely.

Enter a web address

Advanced options

Enter your HTML code

Advanced options

Select a file

Advanced options

To use the API you must first generate your own personal key

Enter your email address below to receive a key

API Guide

To use the API simply make a POST request to http://converthtmltopdf.com. At minimum you must include your API key and the content (as a URL or raw HTML) but there are several other options available.

Option name Description Required?
ApiKey Your API key, this lets you use the API. Yes
Content The HTML you want converted to a PDF. Either as a URL or the raw HTML itself. Yes
PageOrientation The orientation of the pages. Options are Portrait or Landscape. No
PageSize The size of the pages. Options are A4, A3, Letter. No
PageHeight The page height in mm. No
PageWidth The page width in mm. No
TopMargin The top margin in mm. No
BottomMargin The bottom margin in mm. No
LeftMargin The left margin in mm. No
RightMargin The top margin in mm. No
Zoom The zoom to be used. No
GreyScale Set this to true for a greyscale document No
FileName The name of the PDF file to be generated No
More coming soon...

API Examples

.Net Framework

Saving a file to disk
        
            public async Task GetPdf()
            {
                var client = new HttpClient();

                var values = new
                {
                     ApiKey = "ABC123",
                     Content = "http://www.google.com"
                     //Add extra options here
                };

                var request = new HttpRequestMessage
                {
                    RequestUri = new Uri("https://converthtmltopdf.com/Api"),
                    Method = HttpMethod.Post,
                    Content = new StringContent(JsonConvert.SerializeObject(values))
                };

                request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                var response = await client.SendAsync(request);
                response.EnsureSuccessStatusCode();

                var stream = await response.Content.ReadAsStreamAsync();
                MemoryStream mem = new MemoryStream();
                stream.CopyTo(mem);

                System.IO.File.WriteAllBytes("C:\\FolderLocation\\fileName.pdf", mem.ToArray());
            }
        

.Net Core

Returning a file from a controller
    
        public async Task GetPdf()
        {
            var client = new HttpClient();

            var values = new
            {
                ApiKey = "ABC123",
                Content = "http://www.google.com"
                //Add extra options here
            };

            var request = new HttpRequestMessage
            {
                RequestUri = new Uri("https://converthtmltopdf.com/Api"),
                Method = HttpMethod.Post,
                Content = new StringContent(JsonConvert.SerializeObject(values))
            };

            request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            var response = await client.SendAsync(request);
            response.EnsureSuccessStatusCode();

            var stream = await response.Content.ReadAsStreamAsync();

            return File(stream, "application/pdf");
        }
    

JavaScript

Saving a file
    
     
            function getPdf() {
                var xhr = new XMLHttpRequest();

                var data = {
                    apiKey: "ABC123",
                    content:  "http://www.google.com"
                    //Add extra options here
                };

                xhr.onload = function() {
                    var blob = xhr.response;
                    var fileName = "yourfile.pdf";
                    saveBlob(blob, fileName);
                };

                xhr.open("POST", "https://converthtmltopdf/Api", true);
                xhr.setRequestHeader("Content-Type", "application/json");
                xhr.responseType = "blob";
                xhr.send(JSON.stringify(data));
            }

            function saveBlob(blob, fileName) {

                if (window.navigator.msSaveOrOpenBlob) {
                    ieSaveBlob(blob, fileName);
                } else {

                    var a = document.createElement("a");
                    var url = window.URL.createObjectURL(blob);
                    a.href = url;

                    a.download = fileName;
                    document.body.appendChild(a);

                    a.click();

                    setTimeout(function() {
                            document.body.removeChild(a);
                            window.URL.revokeObjectURL(url);
                        },
                        100);
                }
            }

            function ieSaveBlob(blob, fileName) {
                var a = document.createElement("a");
                document.body.appendChild(a);

                a.onclick = function() {
                    window.navigator.msSaveOrOpenBlob(blob, fileName);
                };

                a.click();

                setTimeout(function () {
                    document.body.removeChild(a);
                }, 100); 
            }
    

Contact Us

If you have any comments, questions or feedback please use the form below.