Learn how to convert web pages and HTML documents to PDF in .Net using the Pdfcrowd API v2. The API is easy to use and the integration takes only a couple of lines of code.
Learn more about other install options.
Authentication is needed in order to use the Pdfcrowd API. The credentials
used for accessing the API are your Pdfcrowd username and the API key.
Sign up for a Free Trial
using System; using System.IO; public class ApiTest { public static void Main() { try { // create the API client instance pdfcrowd.HtmlToPdfClient client = new pdfcrowd.HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // run the conversion and write the result to a file client.convertUrlToFile("http://www.example.com", "example.pdf"); } catch(pdfcrowd.Error why) { // report the error System.Console.Error.WriteLine("Pdfcrowd Error: " + why); // rethrow or handle the exception throw; } } }
using System; using System.IO; public class ApiTest { public static void Main() { try { // create the API client instance pdfcrowd.HtmlToPdfClient client = new pdfcrowd.HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // create output file for conversion result FileStream outputFile = new FileStream("example.pdf", FileMode.CreateNew); // run the conversion and store the result into the "pdf" variable byte[] pdf = client.convertUrl("http://www.example.com"); // write the "pdf" variable into the output file outputFile.Write(pdf, 0, pdf.Length); // close the output file outputFile.Close(); } catch(pdfcrowd.Error why) { // report the error System.Console.Error.WriteLine("Pdfcrowd Error: " + why); // rethrow or handle the exception throw; } } }
using System; using System.IO; public class ApiTest { public static void Main() { try { // create the API client instance pdfcrowd.HtmlToPdfClient client = new pdfcrowd.HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // create output stream for conversion result FileStream outputStream = new FileStream("example.pdf", FileMode.CreateNew); // run the conversion and write the result into the output stream client.convertUrlToStream("http://www.example.com", outputStream); // close the output stream outputStream.Close(); } catch(pdfcrowd.Error why) { // report the error System.Console.Error.WriteLine("Pdfcrowd Error: " + why); // rethrow or handle the exception throw; } } }
using System; using System.IO; public class ApiTest { public static void Main() { try { // create the API client instance pdfcrowd.HtmlToPdfClient client = new pdfcrowd.HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // run the conversion and write the result to a file client.convertFileToFile("/path/to/MyLayout.html", "MyLayout.pdf"); } catch(pdfcrowd.Error why) { // report the error System.Console.Error.WriteLine("Pdfcrowd Error: " + why); // rethrow or handle the exception throw; } } }
using System; using System.IO; public class ApiTest { public static void Main() { try { // create the API client instance pdfcrowd.HtmlToPdfClient client = new pdfcrowd.HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // create output file for conversion result FileStream outputFile = new FileStream("MyLayout.pdf", FileMode.CreateNew); // run the conversion and store the result into the "pdf" variable byte[] pdf = client.convertFile("/path/to/MyLayout.html"); // write the "pdf" variable into the output file outputFile.Write(pdf, 0, pdf.Length); // close the output file outputFile.Close(); } catch(pdfcrowd.Error why) { // report the error System.Console.Error.WriteLine("Pdfcrowd Error: " + why); // rethrow or handle the exception throw; } } }
using System; using System.IO; public class ApiTest { public static void Main() { try { // create the API client instance pdfcrowd.HtmlToPdfClient client = new pdfcrowd.HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // create output stream for conversion result FileStream outputStream = new FileStream("MyLayout.pdf", FileMode.CreateNew); // run the conversion and write the result into the output stream client.convertFileToStream("/path/to/MyLayout.html", outputStream); // close the output stream outputStream.Close(); } catch(pdfcrowd.Error why) { // report the error System.Console.Error.WriteLine("Pdfcrowd Error: " + why); // rethrow or handle the exception throw; } } }
using System; using System.IO; public class ApiTest { public static void Main() { try { // create the API client instance pdfcrowd.HtmlToPdfClient client = new pdfcrowd.HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // run the conversion and write the result to a file client.convertStringToFile("<html><body><h1>Hello World!</h1></body></html>", "HelloWorld.pdf"); } catch(pdfcrowd.Error why) { // report the error System.Console.Error.WriteLine("Pdfcrowd Error: " + why); // rethrow or handle the exception throw; } } }
using System; using System.IO; public class ApiTest { public static void Main() { try { // create the API client instance pdfcrowd.HtmlToPdfClient client = new pdfcrowd.HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // create output file for conversion result FileStream outputFile = new FileStream("HelloWorld.pdf", FileMode.CreateNew); // run the conversion and store the result into the "pdf" variable byte[] pdf = client.convertString("<html><body><h1>Hello World!</h1></body></html>"); // write the "pdf" variable into the output file outputFile.Write(pdf, 0, pdf.Length); // close the output file outputFile.Close(); } catch(pdfcrowd.Error why) { // report the error System.Console.Error.WriteLine("Pdfcrowd Error: " + why); // rethrow or handle the exception throw; } } }
using System; using System.IO; public class ApiTest { public static void Main() { try { // create the API client instance pdfcrowd.HtmlToPdfClient client = new pdfcrowd.HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // create output stream for conversion result FileStream outputStream = new FileStream("HelloWorld.pdf", FileMode.CreateNew); // run the conversion and write the result into the output stream client.convertStringToStream("<html><body><h1>Hello World!</h1></body></html>", outputStream); // close the output stream outputStream.Close(); } catch(pdfcrowd.Error why) { // report the error System.Console.Error.WriteLine("Pdfcrowd Error: " + why); // rethrow or handle the exception throw; } } }
using System; using System.IO; public class ApiTest { public static void Main() { try { // create the API client instance pdfcrowd.HtmlToPdfClient client = new pdfcrowd.HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // configure the conversion client.setDebugLog(true); // run the conversion and write the result to a file client.convertFileToFile("/path/to/MyLayout.html", "MyLayout.pdf"); // print URL to the debug log System.Console.WriteLine("Debug log url: " + client.getDebugLogUrl()); // print the number of available conversion credits in your account System.Console.WriteLine("Remaining credit count: " + client.getRemainingCreditCount()); // print the number of credits consumed by the conversion System.Console.WriteLine("Consumed credit count: " + client.getConsumedCreditCount()); // print the unique ID of the conversion System.Console.WriteLine("Job id: " + client.getJobId()); // print the total number of pages in the output document System.Console.WriteLine("Page count: " + client.getPageCount()); // print the size of the output in bytes System.Console.WriteLine("Output size: " + client.getOutputSize()); } catch(pdfcrowd.Error why) { // report the error System.Console.Error.WriteLine("Pdfcrowd Error: " + why); // rethrow or handle the exception throw; } } }
using System; using System.IO; public class ApiTest { public static void Main() { try { // create the API client instance pdfcrowd.HtmlToPdfClient client = new pdfcrowd.HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // configure the conversion client.setPageSize("Letter"); client.setOrientation("landscape"); client.setNoMargins(true); // run the conversion and write the result to a file client.convertUrlToFile("http://www.example.com", "letter_landscape.pdf"); } catch(pdfcrowd.Error why) { // report the error System.Console.Error.WriteLine("Pdfcrowd Error: " + why); // rethrow or handle the exception throw; } } }
using System; using System.IO; public class ApiTest { public static void Main() { try { // create the API client instance pdfcrowd.HtmlToPdfClient client = new pdfcrowd.HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // configure the conversion client.setHeaderHeight("15mm"); client.setFooterHeight("10mm"); client.setHeaderHtml("<a class='pdfcrowd-source-url' data-pdfcrowd-placement='href-and-content'></a>"); client.setFooterHtml("<center><span class='pdfcrowd-page-number'></span></center>"); client.setMarginTop("0mm"); client.setMarginBottom("0mm"); // run the conversion and write the result to a file client.convertUrlToFile("http://www.example.com", "header_footer.pdf"); } catch(pdfcrowd.Error why) { // report the error System.Console.Error.WriteLine("Pdfcrowd Error: " + why); // rethrow or handle the exception throw; } } }
using System; using System.IO; public class ApiTest { public static void Main() { try { // create the API client instance pdfcrowd.HtmlToPdfClient client = new pdfcrowd.HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // configure the conversion client.setScaleFactor(300); // run the conversion and write the result to a file client.convertUrlToFile("http://www.example.com", "zoom_300.pdf"); } catch(pdfcrowd.Error why) { // report the error System.Console.Error.WriteLine("Pdfcrowd Error: " + why); // rethrow or handle the exception throw; } } }
using System; using System.IO; public class ApiTest { public static void Main() { try { // create the API client instance pdfcrowd.HtmlToPdfClient client = new pdfcrowd.HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // configure the conversion client.setAuthor("Pdfcrowd"); client.setTitle("Hello"); client.setSubject("Demo"); client.setKeywords("Pdfcrowd,demo"); // run the conversion and write the result to a file client.convertUrlToFile("http://www.example.com", "with_metadata.pdf"); } catch(pdfcrowd.Error why) { // report the error System.Console.Error.WriteLine("Pdfcrowd Error: " + why); // rethrow or handle the exception throw; } } }
using System; using System.IO; public class ApiTest { public static void Main() { try { // create the API client instance pdfcrowd.HtmlToPdfClient client = new pdfcrowd.HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // configure the conversion client.setPageLayout("single-page"); client.setPageMode("full-screen"); client.setInitialZoomType("fit-page"); client.setOrientation("landscape"); client.setNoMargins(true); // run the conversion and write the result to a file client.convertUrlToFile("https://pdfcrowd.com/doc/api/", "slide_show.pdf"); } catch(pdfcrowd.Error why) { // report the error System.Console.Error.WriteLine("Pdfcrowd Error: " + why); // rethrow or handle the exception throw; } } }
using System; using System.IO; public class ApiTest { public static void Main() { try { // create the API client instance pdfcrowd.HtmlToPdfClient client = new pdfcrowd.HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // configure the conversion client.setElementToConvert("#main"); // run the conversion and write the result to a file client.convertUrlToFile("https://pdfcrowd.com/doc/api/", "html_part.pdf"); } catch(pdfcrowd.Error why) { // report the error System.Console.Error.WriteLine("Pdfcrowd Error: " + why); // rethrow or handle the exception throw; } } }
using System; using System.IO; public class ApiTest { public static void Main() { try { // create the API client instance pdfcrowd.HtmlToPdfClient client = new pdfcrowd.HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // configure the conversion client.setCustomJavascript("el=document.createElement('h2'); el.textContent='Hello from Pdfcrowd API'; el.style.color='red'; el_before=document.getElementsByTagName('h1')[0]; el_before.parentNode.insertBefore(el, el_before.nextSibling)"); // run the conversion and write the result to a file client.convertUrlToFile("http://www.example.com", "html_inject.pdf"); } catch(pdfcrowd.Error why) { // report the error System.Console.Error.WriteLine("Pdfcrowd Error: " + why); // rethrow or handle the exception throw; } } }
using System; using System.IO; public class ApiTest { public static void Main() { try { // create the API client instance pdfcrowd.HtmlToPdfClient client = new pdfcrowd.HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // configure the conversion client.setViewportWidth(992); client.setRenderingMode("viewport"); client.setSmartScalingMode("viewport-fit"); client.setNoMargins(true); // run the conversion and write the result to a file client.convertUrlToFile("https://getbootstrap.com/", "bootstrap.pdf"); } catch(pdfcrowd.Error why) { // report the error System.Console.Error.WriteLine("Pdfcrowd Error: " + why); // rethrow or handle the exception throw; } } }
using System; using System.IO; public class ApiTest { public static void Main() { try { // create the API client instance pdfcrowd.HtmlToPdfClient client = new pdfcrowd.HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // configure the conversion client.setCustomJavascript("libPdfcrowd.highlightHtmlElements({backgroundColor: 'rgba(255, 191, 0, 0.1)', borderColor:null})"); // run the conversion and write the result to a file client.convertUrlToFile("http://www.example.com", "highlight_background.pdf"); } catch(pdfcrowd.Error why) { // report the error System.Console.Error.WriteLine("Pdfcrowd Error: " + why); // rethrow or handle the exception throw; } } }
using System; using System.IO; public class ApiTest { public static void Main() { try { // create the API client instance pdfcrowd.HtmlToPdfClient client = new pdfcrowd.HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // configure the conversion client.setCustomJavascript("libPdfcrowd.highlightHtmlElements({borderColor: 'orange', backgroundColor: null, padding: '4px', margin: '4px'})"); // run the conversion and write the result to a file client.convertUrlToFile("http://www.example.com", "highlight_borders.pdf"); } catch(pdfcrowd.Error why) { // report the error System.Console.Error.WriteLine("Pdfcrowd Error: " + why); // rethrow or handle the exception throw; } } }
The API can be easily integrated into your environment. You can have our interactive API Playground autogenerate the integration code for you:
You can also check out a complete example in our pdfcrowd-examples Github repository:
The API lets you convert a web page, a local HTML file, or a string containing HTML. The result of the conversion can be stored to a local file, to a stream object or to a variable. See the conversion input section for more details.
The best way to start with the API is to choose one of the examples and once you get it working, you can further customize the code. You can find the most common customizations in the table below.
Page size | Change the page size with setPageSize or setPageDimensions. Pass -1 to setPageHeight to get a single page PDF containing the whole document. |
Page orientation | Change the page orientation to landscape with setOrientation. |
Page margins | Adjust the page margins with setPageMargins. |
Headers and footers | Add headers and footers with setHeaderHtml and setFooterHtml. Set the height with setFooterHeight and setHeaderHeight. |
Zoom | Scale the HTML contents with setScaleFactor. |
Hide or remove elements |
You can use the following classes in your HTML code to hide or remove elements from the output:
|
Use @media print | You can switch to the print version of the page (if it exists) with setUsePrintMedia. |
Force page break |
You can force a page break with<div style="page-break-before:always"></div>
|
Avoid page break |
You can avoid a page break inside an element with the following CSSth, td, img { page-break-inside:avoid }
|
Run custom JavaScript | You can use setOnLoadJavascript or setCustomJavascript to alter the HTML contents with a custom JavaScript. In addition to the standard browser APIs, the custom JavaScript code can use helper functions from our JavaScript library. |
The API enables rendering of HTML templates. The template syntax is based on the Jinja template rendering engine.
The most common constructs are:
Invoice: {{ invoice.number }}
{% for invoice in invoices %} ... {% endfor %}
{% if invoice.total > 100 %} ... {% endif %}
{{ invoice.to.first_name|capitalize }}
The supported input data formats are JSON, XML, CSV and YAML. The data can be uploaded from a file or from a string variable.
Supported template filters: capitalize, center, default, escape, first, forceescape, format, indent, join, last, length, list, lower, replace, reverse, safe, slice, sort, string, striptags, title, trim, truncate, unique, upper, wordcount, wordwrap.
using System; using System.IO; public class ApiTest { public static void Main() { try { // create the API client instance pdfcrowd.HtmlToPdfClient client = new pdfcrowd.HtmlToPdfClient("{{ user_name }}", "{{ api_key }}"); // configure the conversion client.setDataString(@"{ ""name"": ""World"", ""product"": ""Pdfcrowd API"" }"); // run the conversion and write the result to a file client.convertStringToFile("Hello {{ name }} from {{ product }}", "output.pdf"); } catch(pdfcrowd.Error why) { // report the error System.Console.Error.WriteLine("Pdfcrowd Error: " + why); // rethrow or handle the exception throw; } } }
using System; using System.IO; public class ApiTest { public static void Main() { try { // create the API client instance pdfcrowd.HtmlToPdfClient client = new pdfcrowd.HtmlToPdfClient("{{ user_name }}", "{{ api_key }}"); // configure the conversion client.setDataString(@"<?xml version=""1.0"" encoding=""UTF-8""?> <data> <name>World</name> <product>Pdfcrowd API</product> </data>"); // run the conversion and write the result to a file client.convertStringToFile("Hello {{ data.name }} from {{ data.product }}", "output.pdf"); } catch(pdfcrowd.Error why) { // report the error System.Console.Error.WriteLine("Pdfcrowd Error: " + why); // rethrow or handle the exception throw; } } }
using System; using System.IO; public class ApiTest { public static void Main() { try { // create the API client instance pdfcrowd.HtmlToPdfClient client = new pdfcrowd.HtmlToPdfClient("{{ user_name }}", "{{ api_key }}"); // configure the conversion client.setDataString(@"name: World product: Pdfcrowd API"); // run the conversion and write the result to a file client.convertStringToFile("Hello {{ name }} from {{ product }}", "output.pdf"); } catch(pdfcrowd.Error why) { // report the error System.Console.Error.WriteLine("Pdfcrowd Error: " + why); // rethrow or handle the exception throw; } } }
using System; using System.IO; public class ApiTest { public static void Main() { try { // create the API client instance pdfcrowd.HtmlToPdfClient client = new pdfcrowd.HtmlToPdfClient("{{ user_name }}", "{{ api_key }}"); // configure the conversion client.setDataString(@"name,product World,Pdfcrowd API"); // run the conversion and write the result to a file client.convertStringToFile("Hello {{ name }} from {{ product }}", "output.pdf"); } catch(pdfcrowd.Error why) { // report the error System.Console.Error.WriteLine("Pdfcrowd Error: " + why); // rethrow or handle the exception throw; } } }
try { // call the API } catch(pdfcrowd.Error why) { // print error System.Console.Error.WriteLine("Pdfcrowd Error: " + why); // print just error code System.Console.Error.WriteLine("Pdfcrowd Error Code: " + why.getCode()); // print just error message System.Console.Error.WriteLine("Pdfcrowd Error Message: " + why.getMessage()); // or handle the error in your way }
libPdfcrowd.highlightHtmlElements
method call to visualize all HTML elements. See the example and helper JavaScript library documentation.
Conversion from HTML to PDF. All setter methods return HtmlToPdfClient object unless otherwise specified.
public HtmlToPdfClient(string userName, string apiKey)
userName
Your username at Pdfcrowd.
|
apiKey
Your API key.
|
public byte[] convertUrl(string url)
url
The address of the web page to convert.
The supported protocols are http:// and https://.
|
public void convertUrlToStream(string url, Stream outStream)
url
The address of the web page to convert.
The supported protocols are http:// and https://.
|
outStream
The output stream that will contain the conversion output.
|
public void convertUrlToFile(string url, string filePath)
url
The address of the web page to convert.
The supported protocols are http:// and https://.
|
filePath
The output file path.
The string must not be empty.
|
public byte[] convertFile(string file)
file
The path to a local file to convert.
The file can be either a single file or an archive (.tar.gz, .tar.bz2, or .zip). If the HTML document refers to local external assets (images, style sheets, javascript), zip the document together with the assets. The file must exist and not be empty.
The file name must have a valid extension.
|
public void convertFileToStream(string file, Stream outStream)
file
The path to a local file to convert.
The file can be either a single file or an archive (.tar.gz, .tar.bz2, or .zip). If the HTML document refers to local external assets (images, style sheets, javascript), zip the document together with the assets. The file must exist and not be empty.
The file name must have a valid extension.
|
outStream
The output stream that will contain the conversion output.
|
public void convertFileToFile(string file, string filePath)
file
The path to a local file to convert.
The file can be either a single file or an archive (.tar.gz, .tar.bz2, or .zip). If the HTML document refers to local external assets (images, style sheets, javascript), zip the document together with the assets. The file must exist and not be empty.
The file name must have a valid extension.
|
filePath
The output file path.
The string must not be empty.
|
public byte[] convertString(string text)
text
The string content to convert.
The string must not be empty.
|
public void convertStringToStream(string text, Stream outStream)
text
The string content to convert.
The string must not be empty.
|
outStream
The output stream that will contain the conversion output.
|
public void convertStringToFile(string text, string filePath)
text
The string content to convert.
The string must not be empty.
|
filePath
The output file path.
The string must not be empty.
|
public HtmlToPdfClient setPageSize(string pageSize)
pageSize
Allowed values:
Default: A4
|
public HtmlToPdfClient setPageWidth(string pageWidth)
pageWidth
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 8.27in
|
setPageWidth("300mm")
setPageWidth("9.5in")
public HtmlToPdfClient setPageHeight(string pageHeight)
pageHeight
Can be -1 or specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 11.7in
|
setPageHeight("350mm")
setPageHeight("15.25in")
setPageHeight("-1")
public HtmlToPdfClient setPageDimensions(string width, string height)
width
Set the output page width. The safe maximum is 200in otherwise some PDF viewers may be unable to open the PDF.
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 8.27in
|
height
Set the output page height. Use -1 for a single page PDF. The safe maximum is 200in otherwise some PDF viewers may be unable to open the PDF.
Can be -1 or specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 11.7in
|
setPageDimensions("300mm", "350mm")
setPageDimensions("9.5in", "15.25in")
setPageDimensions("372mm", "520pt")
public HtmlToPdfClient setOrientation(string orientation)
orientation
Allowed values:
Default: portrait
|
public HtmlToPdfClient setMarginTop(string marginTop)
marginTop
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 0.4in
|
setMarginTop("1in")
setMarginTop("2.5cm")
public HtmlToPdfClient setMarginRight(string marginRight)
marginRight
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 0.4in
|
setMarginRight("1in")
setMarginRight("2.5cm")
public HtmlToPdfClient setMarginBottom(string marginBottom)
marginBottom
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 0.4in
|
setMarginBottom("1in")
setMarginBottom("2.5cm")
public HtmlToPdfClient setMarginLeft(string marginLeft)
marginLeft
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 0.4in
|
setMarginLeft("1in")
setMarginLeft("2.5cm")
public HtmlToPdfClient setNoMargins(bool noMargins)
noMargins
Set to true to disable margins.
Default: false
|
public HtmlToPdfClient setPageMargins(string top, string right, string bottom, string left)
top
Set the output page top margin.
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 0.4in
|
right
Set the output page right margin.
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 0.4in
|
bottom
Set the output page bottom margin.
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 0.4in
|
left
Set the output page left margin.
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 0.4in
|
public HtmlToPdfClient setHeaderUrl(string headerUrl)
headerUrl
The supported protocols are http:// and https://.
|
setHeaderUrl("http://myserver.com/header.html")
public HtmlToPdfClient setHeaderHtml(string headerHtml)
headerHtml
The string must not be empty.
|
setHeaderHtml("Page <span class='pdfcrowd-page-number'></span> of <span class='pdfcrowd-page-count'></span> pages")
public HtmlToPdfClient setHeaderHeight(string headerHeight)
headerHeight
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 0.5in
|
setHeaderHeight("30mm")
setHeaderHeight("1in")
footerUrl
The supported protocols are http:// and https://.
|
setFooterUrl("http://myserver.com/header.html")
footerHtml
The string must not be empty.
|
setFooterHtml("Page <span class='pdfcrowd-page-number'></span> of <span class='pdfcrowd-page-count'></span> pages")
footerHeight
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: 0.5in
|
setFooterHeight("30mm")
setFooterHeight("1in")
public HtmlToPdfClient setPrintPageRange(string pages)
pages
A comma separated list of page numbers or ranges.
|
setPrintPageRange("2")
setPrintPageRange("1,3")
setPrintPageRange("2-")
setPrintPageRange("-3")
setPrintPageRange("3,6-9")
public HtmlToPdfClient setExcludeHeaderOnPages(string pages)
pages
List of physical page numbers. Negative numbers count backwards from the last page: -1 is the last page, -2 is the last but one page, and so on.
A comma separated list of page numbers.
|
setExcludeHeaderOnPages("2")
setExcludeHeaderOnPages("1,-1")
pages
List of physical page numbers. Negative numbers count backwards from the last page: -1 is the last page, -2 is the last but one page, and so on.
A comma separated list of page numbers.
|
setExcludeFooterOnPages("2")
setExcludeFooterOnPages("1,-1")
public HtmlToPdfClient setPageNumberingOffset(int offset)
offset
Integer specifying page offset.
Default: 0
|
setPageNumberingOffset(1)
setPageNumberingOffset(-10)
public HtmlToPdfClient setContentAreaX(string contentAreaX)
contentAreaX
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt). It may contain a negative value.
Default: 0in
|
setContentAreaX("-1in")
setContentAreaX("2.5cm")
public HtmlToPdfClient setContentAreaY(string contentAreaY)
contentAreaY
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt). It may contain a negative value.
Default: 0in
|
setContentAreaY("-1in")
setContentAreaY("2.5cm")
public HtmlToPdfClient setContentAreaWidth(string contentAreaWidth)
contentAreaWidth
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: The width of the print area.
|
setContentAreaWidth("8in")
setContentAreaWidth("25cm")
public HtmlToPdfClient setContentAreaHeight(string contentAreaHeight)
contentAreaHeight
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: The height of the print area.
|
setContentAreaHeight("8in")
setContentAreaHeight("25cm")
public HtmlToPdfClient setContentArea(string x, string y, string width, string height)
x
Set the top left X coordinate of the content area. It is relative to the top left X coordinate of the print area.
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt). It may contain a negative value.
Default: 0in
|
y
Set the top left Y coordinate of the content area. It is relative to the top left Y coordinate of the print area.
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt). It may contain a negative value.
Default: 0in
|
width
Set the width of the content area. It should be at least 1 inch.
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: The width of the print area.
|
height
Set the height of the content area. It should be at least 1 inch.
Can be specified in inches (in), millimeters (mm), centimeters (cm), or points (pt).
Default: The height of the print area.
|
Methods related to HTML template rendering.
public HtmlToPdfClient setDataString(string dataString)
dataString
The input data string.
|
public HtmlToPdfClient setDataFile(string dataFile)
dataFile
The file path to a local file containing the input data.
|
public HtmlToPdfClient setDataFormat(string dataFormat)
dataFormat
The data format.
Allowed values:
Default: auto
|
public HtmlToPdfClient setDataEncoding(string dataEncoding)
dataEncoding
The data file encoding.
Default: utf-8
|
public HtmlToPdfClient setDataIgnoreUndefined(bool dataIgnoreUndefined)
dataIgnoreUndefined
Set to true to ignore undefined variables.
Default: false
|
public HtmlToPdfClient setDataAutoEscape(bool dataAutoEscape)
dataAutoEscape
Set to true to turn auto escaping on.
Default: false
|
public HtmlToPdfClient setDataTrimBlocks(bool dataTrimBlocks)
dataTrimBlocks
Set to true to turn auto trimming on.
Default: false
|
public HtmlToPdfClient setDataOptions(string dataOptions)
dataOptions
Comma separated list of options.
|
setDataOptions("csv_delimiter=;")
setDataOptions("data_root=rows")
setDataOptions("xml_remove_root=1")
public HtmlToPdfClient setPageWatermark(string pageWatermark)
pageWatermark
The file path to a local watermark PDF file.
The file must exist and not be empty.
|
public HtmlToPdfClient setPageWatermarkUrl(string pageWatermarkUrl)
pageWatermarkUrl
The supported protocols are http:// and https://.
|
setPageWatermarkUrl("http://myserver.com/watermark.pdf")
public HtmlToPdfClient setMultipageWatermark(string multipageWatermark)
multipageWatermark
The file path to a local watermark PDF file.
The file must exist and not be empty.
|
public HtmlToPdfClient setMultipageWatermarkUrl(string multipageWatermarkUrl)
multipageWatermarkUrl
The supported protocols are http:// and https://.
|
setMultipageWatermarkUrl("http://myserver.com/watermark.pdf")
public HtmlToPdfClient setPageBackground(string pageBackground)
pageBackground
The file path to a local background PDF file.
The file must exist and not be empty.
|
public HtmlToPdfClient setPageBackgroundUrl(string pageBackgroundUrl)
pageBackgroundUrl
The supported protocols are http:// and https://.
|
setPageBackgroundUrl("http://myserver.com/background.pdf")
public HtmlToPdfClient setMultipageBackground(string multipageBackground)
multipageBackground
The file path to a local background PDF file.
The file must exist and not be empty.
|
public HtmlToPdfClient setMultipageBackgroundUrl(string multipageBackgroundUrl)
multipageBackgroundUrl
The supported protocols are http:// and https://.
|
setMultipageBackgroundUrl("http://myserver.com/background.pdf")
public HtmlToPdfClient setPageBackgroundColor(string pageBackgroundColor)
pageBackgroundColor
The value must be in RRGGBB or RRGGBBAA hexadecimal format.
|
setPageBackgroundColor("FF0000")
setPageBackgroundColor("00ff00")
setPageBackgroundColor("00ff0080")
public HtmlToPdfClient setNoBackground(bool noBackground)
noBackground
Set to true to disable the background graphics.
Default: false
|
public HtmlToPdfClient setDisableJavascript(bool disableJavascript)
disableJavascript
Set to true to disable JavaScript in web pages.
Default: false
|
public HtmlToPdfClient setDisableImageLoading(bool disableImageLoading)
disableImageLoading
Set to true to disable loading of images.
Default: false
|
public HtmlToPdfClient setDisableRemoteFonts(bool disableRemoteFonts)
disableRemoteFonts
Set to true disable loading remote fonts.
Default: false
|
public HtmlToPdfClient setBlockAds(bool blockAds)
blockAds
Set to true to block ads in web pages.
Default: false
|
public HtmlToPdfClient setDefaultEncoding(string defaultEncoding)
defaultEncoding
The text encoding of the HTML content.
Default: auto detect
|
public HtmlToPdfClient setHttpAuth(string userName, string password)
userName
Set the HTTP authentication user name.
|
password
Set the HTTP authentication password.
|
public HtmlToPdfClient setUsePrintMedia(bool usePrintMedia)
usePrintMedia
Set to true to use the print version of the page.
Default: false
|
public HtmlToPdfClient setNoXpdfcrowdHeader(bool noXpdfcrowdHeader)
noXpdfcrowdHeader
Set to true to disable sending X-Pdfcrowd HTTP header.
Default: false
|
public HtmlToPdfClient setCookies(string cookies)
cookies
The cookie string.
|
setCookies("session=6d7184b3bf35;token=2710")
public HtmlToPdfClient setVerifySslCertificates(bool verifySslCertificates)
verifySslCertificates
Set to true to enable SSL certificate verification.
Default: false
|
public HtmlToPdfClient setFailOnMainUrlError(bool failOnError)
failOnError
Set to true to abort the conversion.
Default: false
|
public HtmlToPdfClient setFailOnAnyUrlError(bool failOnError)
failOnError
Set to true to abort the conversion.
Default: false
|
public HtmlToPdfClient setCustomJavascript(string customJavascript)
customJavascript
A string containing a JavaScript code.
The string must not be empty.
|
public HtmlToPdfClient setOnLoadJavascript(string onLoadJavascript)
onLoadJavascript
A string containing a JavaScript code.
The string must not be empty.
|
public HtmlToPdfClient setCustomHttpHeader(string customHttpHeader)
customHttpHeader
A string containing the header name and value separated by a colon.
|
setCustomHttpHeader("X-My-Client-ID:k2017-12345")
public HtmlToPdfClient setJavascriptDelay(int javascriptDelay)
javascriptDelay
The number of milliseconds to wait.
Must be a positive integer number or 0.
Default: 200
|
public HtmlToPdfClient setElementToConvert(string selectors)
selectors
One or more CSS selectors separated by commas.
The string must not be empty.
|
setElementToConvert("#main-content")
setElementToConvert(".main-content")
setElementToConvert("table")
setElementToConvert("table, #main-content")
setElementToConvert("div.user-panel.main p.article")
public HtmlToPdfClient setElementToConvertMode(string mode)
mode
Allowed values:
Default: cut-out
|
public HtmlToPdfClient setWaitForElement(string selectors)
selectors
One or more CSS selectors separated by commas.
The string must not be empty.
|
setWaitForElement("#main-content")
setWaitForElement(".main-content")
setWaitForElement("table")
setWaitForElement("table, #main-content")
setWaitForElement("div.user-panel.main p.article")
public HtmlToPdfClient setViewportWidth(int viewportWidth)
viewportWidth
The value must be in the range 96-65000.
Default: 1024
|
public HtmlToPdfClient setViewportHeight(int viewportHeight)
viewportHeight
Must be a positive integer number.
Default: 768
|
public HtmlToPdfClient setViewport(int width, int height)
width
Set the viewport width in pixels. The viewport is the user's visible area of the page.
The value must be in the range 96-65000.
Default: 1024
|
height
Set the viewport height in pixels. The viewport is the user's visible area of the page.
Must be a positive integer number.
Default: 768
|
public HtmlToPdfClient setRenderingMode(string renderingMode)
renderingMode
The rendering mode.
Allowed values:
Default: default
|
public HtmlToPdfClient setSmartScalingMode(string smartScalingMode)
smartScalingMode
The smart scaling mode.
Allowed values:
Default: default
|
public HtmlToPdfClient setScaleFactor(int scaleFactor)
scaleFactor
The percentage value.
The value must be in the range 10-500.
Default: 100
|
headerFooterScaleFactor
The percentage value.
The value must be in the range 10-500.
Default: 100
|
public HtmlToPdfClient setDisableSmartShrinking(bool disableSmartShrinking)
disableSmartShrinking
Set to true to disable the intelligent shrinking strategy.
Default: false
|
public HtmlToPdfClient setJpegQuality(int jpegQuality)
jpegQuality
The percentage value.
The value must be in the range 1-100.
Default: 100
|
public HtmlToPdfClient setConvertImagesToJpeg(string convertImagesToJpeg)
convertImagesToJpeg
The image category.
Allowed values:
Default: none
|
public HtmlToPdfClient setImageDpi(int imageDpi)
imageDpi
The DPI value.
Must be a positive integer number or 0.
Default: 0
|
setImageDpi(0)
setImageDpi(72)
setImageDpi(96)
setImageDpi(150)
setImageDpi(300)
Miscellaneous values for PDF output.
public HtmlToPdfClient setLinearize(bool linearize)
linearize
Set to true to create linearized PDF.
Default: false
|
public HtmlToPdfClient setEncrypt(bool encrypt)
encrypt
Set to true to enable PDF encryption.
Default: false
|
public HtmlToPdfClient setUserPassword(string userPassword)
userPassword
The user password.
|
public HtmlToPdfClient setOwnerPassword(string ownerPassword)
ownerPassword
The owner password.
|
public HtmlToPdfClient setNoPrint(bool noPrint)
noPrint
Set to true to set the no-print flag in the output PDF.
Default: false
|
public HtmlToPdfClient setNoModify(bool noModify)
noModify
Set to true to set the read-only only flag in the output PDF.
Default: false
|
public HtmlToPdfClient setNoCopy(bool noCopy)
noCopy
Set to true to set the no-copy flag in the output PDF.
Default: false
|
public HtmlToPdfClient setTitle(string title)
title
The title.
|
public HtmlToPdfClient setSubject(string subject)
subject
The subject.
|
public HtmlToPdfClient setAuthor(string author)
author
The author.
|
public HtmlToPdfClient setKeywords(string keywords)
keywords
The string with the keywords.
|
These preferences specify how a PDF viewer should present the document. The preferences may be ignored by some PDF viewers.
public HtmlToPdfClient setPageLayout(string pageLayout)
pageLayout
Allowed values:
|
public HtmlToPdfClient setPageMode(string pageMode)
pageMode
Allowed values:
|
public HtmlToPdfClient setInitialZoomType(string initialZoomType)
initialZoomType
Allowed values:
|
public HtmlToPdfClient setInitialPage(int initialPage)
initialPage
Must be a positive integer number.
|
public HtmlToPdfClient setInitialZoom(int initialZoom)
initialZoom
Must be a positive integer number.
|
public HtmlToPdfClient setHideToolbar(bool hideToolbar)
hideToolbar
Set to true to hide tool bars.
Default: false
|
hideMenubar
Set to true to hide the menu bar.
Default: false
|
public HtmlToPdfClient setHideWindowUi(bool hideWindowUi)
hideWindowUi
Set to true to hide ui elements.
Default: false
|
public HtmlToPdfClient setFitWindow(bool fitWindow)
fitWindow
Set to true to resize the window.
Default: false
|
public HtmlToPdfClient setCenterWindow(bool centerWindow)
centerWindow
Set to true to center the window.
Default: false
|
public HtmlToPdfClient setDisplayTitle(bool displayTitle)
displayTitle
Set to true to display the title.
Default: false
|
public HtmlToPdfClient setRightToLeft(bool rightToLeft)
rightToLeft
Set to true to set right-to-left reading order.
Default: false
|
public HtmlToPdfClient setDebugLog(bool debugLog)
debugLog
Set to true to enable the debug logging.
Default: false
|
public string getDebugLogUrl()
public int getRemainingCreditCount()
public int getConsumedCreditCount()
public string getJobId()
public int getPageCount()
public int getOutputSize()
public HtmlToPdfClient setTag(string tag)
tag
A string with the custom tag.
|
public HtmlToPdfClient setHttpProxy(string httpProxy)
httpProxy
The value must have format DOMAIN_OR_IP_ADDRESS:PORT.
|
setHttpProxy("myproxy.com:8080")
setHttpProxy("113.25.84.10:33333")
public HtmlToPdfClient setHttpsProxy(string httpsProxy)
httpsProxy
The value must have format DOMAIN_OR_IP_ADDRESS:PORT.
|
setHttpsProxy("myproxy.com:443")
setHttpsProxy("113.25.84.10:44333")
public HtmlToPdfClient setClientCertificate(string clientCertificate)
clientCertificate
The file must be in PKCS12 format.
The file must exist and not be empty.
|
public HtmlToPdfClient setClientCertificatePassword(string clientCertificatePassword)
clientCertificatePassword
|
public HtmlToPdfClient setUseHttp(bool useHttp)
useHttp
Set to true to use HTTP.
Default: false
|
Warning
Using HTTP is insecure as data sent over HTTP is not encrypted. Enable this option only if you know what you are doing.
public HtmlToPdfClient setUserAgent(string userAgent)
userAgent
The user agent string.
Default: pdfcrowd_dotnet_client/4.12.0 (http://pdfcrowd.com)
|
public HtmlToPdfClient setProxy(string host, int port, string userName, string password)
host
The proxy hostname.
|
port
The proxy port.
|
userName
The username.
|
password
The password.
|
public HtmlToPdfClient setRetryCount(int retryCount)
retryCount
Number of retries wanted.
Default: 1
|