HTML to PDF / .NET Reference

class HtmlToPdfClient

All setter methods return HtmlToPdfClient object unless specified otherwise.

Constructor

public HtmlToPdfClient(string userName, string apiKey)

Constructor for the PDFCrowd API client.

Parameters:
  • userName - Your username at PDFCrowd.
  • apiKey - Your API key.

Conversion Input

public byte[] convertUrl(string url)

Convert a web page.

Parameter:
  • url - The address of the web page to convert.
    Constraint:
    • Supported protocols are http:// and https://.
Returns:
byte[] - Byte array containing the conversion output.

public void convertUrlToStream(string url, Stream outStream)

Convert a web page and write the result to an output stream.

Parameters:
  • url - The address of the web page to convert.
    Constraint:
    • Supported protocols are http:// and https://.
  • outStream (OutputStream) - The output stream that will contain the conversion output.

public void convertUrlToFile(string url, string filePath)

Convert a web page and write the result to a local file.

Parameters:
  • url - The address of the web page to convert.
    Constraint:
    • Supported protocols are http:// and https://.
  • filePath - The output file path.

public byte[] convertFile(string file)

Convert a local file.

Parameter:
  • 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.
    Constraints:
    • The file must exist and not be empty.
    • The file name must have a valid extension.
Returns:
byte[] - Byte array containing the conversion output.

public void convertFileToStream(string file, Stream outStream)

Convert a local file and write the result to an output stream.

Parameters:
  • 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.
    Constraints:
    • The file must exist and not be empty.
    • The file name must have a valid extension.
  • outStream (OutputStream) - The output stream that will contain the conversion output.

public void convertFileToFile(string file, string filePath)

Convert a local file and write the result to a local file.

Parameters:
  • 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.
    Constraints:
    • The file must exist and not be empty.
    • The file name must have a valid extension.
  • filePath - The output file path.

public byte[] convertString(string text)

Convert a string.

Parameter:
  • text - The string content to convert.
Returns:
byte[] - Byte array containing the conversion output.

public void convertStringToStream(string text, Stream outStream)

Convert a string and write the output to an output stream.

Parameters:
  • text - The string content to convert.
  • outStream (OutputStream) - The output stream that will contain the conversion output.

public void convertStringToFile(string text, string filePath)

Convert a string and write the output to a file.

Parameters:
  • text - The string content to convert.
  • filePath - The output file path.

public byte[] convertStream(Stream inStream)

Convert the contents of an input stream.

Parameter:
  • inStream (InputStream) - The input stream with source data.
    The stream can contain either HTML code or an archive (.zip, .tar.gz, .tar.bz2).
    The archive can contain HTML code and its external assets (images, style sheets, javascript).
Returns:
byte[] - Byte array containing the conversion output.

public void convertStreamToStream(Stream inStream, Stream outStream)

Convert the contents of an input stream and write the result to an output stream.

Parameters:
  • inStream (InputStream) - The input stream with source data.
    The stream can contain either HTML code or an archive (.zip, .tar.gz, .tar.bz2).
    The archive can contain HTML code and its external assets (images, style sheets, javascript).
  • outStream (OutputStream) - The output stream that will contain the conversion output.

public void convertStreamToFile(Stream inStream, string filePath)

Convert the contents of an input stream and write the result to a local file.

Parameters:
  • inStream (InputStream) - The input stream with source data.
    The stream can contain either HTML code or an archive (.zip, .tar.gz, .tar.bz2).
    The archive can contain HTML code and its external assets (images, style sheets, javascript).
  • filePath - The output file path.

public HtmlToPdfClient setZipMainFilename(string filename)

Set the file name of the main HTML document stored in the input archive. If not specified, the first HTML file in the archive is used for conversion. Use this method if the input archive contains multiple HTML documents.

Parameter:
  • filename - The file name.

Page Setup

public HtmlToPdfClient setPageSize(string size)

Set the output page size.

Parameter:
  • size
    Allowed Values:
    • A0
    • A1
    • A2
    • A3
    • A4
    • A5
    • A6
    • Letter
    Default:
    A4

public HtmlToPdfClient setPageWidth(string width)

Set the output page width. The safe maximum is 200in otherwise some PDF viewers may be unable to open the PDF.

Parameter:
  • width
    Constraint:
    • The value must be specified in inches 'in', millimeters 'mm', centimeters 'cm', pixels 'px', or points 'pt'.
    Default:
    8.27in
Examples:
  • A4 landscape / A3 portrait width: setPageWidth("297mm")
  • US Letter/Legal standard width: setPageWidth("8.5in")

public HtmlToPdfClient setPageHeight(string 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.

Parameter:
  • height
    Constraint:
    • The value must be -1 or specified in inches 'in', millimeters 'mm', centimeters 'cm', pixels 'px', or points 'pt'.
    Default:
    11.7in
Examples:
  • A3 standard height for large format: setPageHeight("420mm")
  • Auto-fit entire content in single page: setPageHeight("-1")
  • US Legal for contracts and documents: setPageHeight("14in")

public HtmlToPdfClient setPageDimensions(string width, string height)

Set the output page dimensions.

Parameters:
  • width - Set the output page width. The safe maximum is 200in otherwise some PDF viewers may be unable to open the PDF.
    Constraint:
    • The value must be specified in inches 'in', millimeters 'mm', centimeters 'cm', pixels 'px', 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.
    Constraint:
    • The value must be -1 or specified in inches 'in', millimeters 'mm', centimeters 'cm', pixels 'px', or points 'pt'.
    Default:
    11.7in
Examples:
  • A4 portrait dimensions: setPageDimensions("210mm", "297mm")
  • US Letter dimensions: setPageDimensions("8.5in", "11in")
  • A3 portrait dimensions: setPageDimensions("297mm", "420mm")

public HtmlToPdfClient setOrientation(string orientation)

Set the output page orientation.

Parameter:
  • orientation
    Allowed Values:
    • landscape
    • portrait
    Default:
    portrait

public HtmlToPdfClient setMarginTop(string top)

Set the output page top margin.

Parameter:
  • top
    Constraint:
    • The value must be specified in inches 'in', millimeters 'mm', centimeters 'cm', pixels 'px', or points 'pt'.
    Default:
    0.4in
Examples:
  • Wide margin for binding: setMarginTop("1in")
  • Narrow professional margin: setMarginTop("10mm")

public HtmlToPdfClient setMarginRight(string right)

Set the output page right margin.

Parameter:
  • right
    Constraint:
    • The value must be specified in inches 'in', millimeters 'mm', centimeters 'cm', pixels 'px', or points 'pt'.
    Default:
    0.4in
Examples:
  • Wide margin for binding: setMarginRight("1in")
  • Narrow professional margin: setMarginRight("10mm")

public HtmlToPdfClient setMarginBottom(string bottom)

Set the output page bottom margin.

Parameter:
  • bottom
    Constraint:
    • The value must be specified in inches 'in', millimeters 'mm', centimeters 'cm', pixels 'px', or points 'pt'.
    Default:
    0.4in
Examples:
  • Wide margin for binding: setMarginBottom("1in")
  • Narrow professional margin: setMarginBottom("10mm")

public HtmlToPdfClient setMarginLeft(string left)

Set the output page left margin.

Parameter:
  • left
    Constraint:
    • The value must be specified in inches 'in', millimeters 'mm', centimeters 'cm', pixels 'px', or points 'pt'.
    Default:
    0.4in
Examples:
  • Wide margin for binding: setMarginLeft("1in")
  • Narrow professional margin: setMarginLeft("10mm")

public HtmlToPdfClient setNoMargins(bool value)

Disable page margins.

Parameter:
  • value (bool) - Set to true to disable margins.
    Default:
    false

public HtmlToPdfClient setPageMargins(string top, string right, string bottom, string left)

Set the output page margins.

Parameters:
  • top - Set the output page top margin.
    Constraint:
    • The value must be specified in inches 'in', millimeters 'mm', centimeters 'cm', pixels 'px', or points 'pt'.
    Default:
    0.4in
  • right - Set the output page right margin.
    Constraint:
    • The value must be specified in inches 'in', millimeters 'mm', centimeters 'cm', pixels 'px', or points 'pt'.
    Default:
    0.4in
  • bottom - Set the output page bottom margin.
    Constraint:
    • The value must be specified in inches 'in', millimeters 'mm', centimeters 'cm', pixels 'px', or points 'pt'.
    Default:
    0.4in
  • left - Set the output page left margin.
    Constraint:
    • The value must be specified in inches 'in', millimeters 'mm', centimeters 'cm', pixels 'px', or points 'pt'.
    Default:
    0.4in

public HtmlToPdfClient setPrintPageRange(string pages)

Set the page range to print.

Parameter:
  • pages
    Constraint:
    • A comma separated list of page numbers or ranges. Special strings may be used, such as 'odd', 'even' and 'last'.
Examples:
  • Just the second page is printed: setPrintPageRange("2")
  • The first, third, and last pages are printed: setPrintPageRange("1,3,last")
  • Everything except the first page is printed: setPrintPageRange("2-")
  • Just first 3 pages are printed: setPrintPageRange("-3")
  • Pages 3, 6, 7, 8 and 9 are printed: setPrintPageRange("3,6-9")

public HtmlToPdfClient setContentViewportWidth(string width)

Set the viewport width for formatting the HTML content when generating a PDF. By specifying a viewport width, you can control how the content is rendered, ensuring it mimics the appearance on various devices or matches specific design requirements.

Availability:
API client >= 6.0.0, converter >= 24.04. See versioning.
Parameter:
  • width - The width of the viewport.
    Allowed Values:
    • balanced — The smart option to adjust the viewport width dynamically to fit the print area, ensuring an optimal layout.
    • small — A compact layout where less text fits on each PDF page, ideal for detailed sections or mobile views.
    • medium — A balanced amount of text per page, striking a good compromise between readability and content density.
    • large — A broader layout that accommodates more text per page, perfect for reducing page count and enhancing flow.
    • extra-large — Maximize the text per page, creating a spacious and content-rich PDF, akin to a widescreen experience.
    • pixel width — A precise viewport width in pixels, such as 1024px, to tailor the PDF's text density to your specific requirements. The value must be in the range 96-65000px.
    Constraint:
    • The value must be 'balanced', 'small', 'medium', 'large', 'extra-large', or a number in the range 96-65000px.
    Default:
    medium
Examples:
  • Use the "large" viewport: setContentViewportWidth("large")
  • Use an 800 pixels wide viewport: setContentViewportWidth("800px")

public HtmlToPdfClient setContentViewportHeight(string height)

Set the viewport height for formatting the HTML content when generating a PDF. By specifying a viewport height, you can enforce loading of lazy-loaded images and also affect vertical positioning of absolutely positioned elements within the content.

Availability:
API client >= 6.0.0, converter >= 24.04. See versioning.
Parameter:
  • height - The viewport height.
    Allowed Values:
    • auto — The height of the print area is used.
    • large — Value suitable for documents with extensive lazy-loaded content.
    • pixel height — A specific numerical value, such as 10000px, to set as the window height, allowing precise control based on the document's requirements.
    Constraint:
    • The value must be 'auto', 'large', or a number.
    Default:
    auto
Examples:
  • Load all lazy images and content: setContentViewportHeight("large")
  • Force tall viewport for long pages: setContentViewportHeight("5000px")

public HtmlToPdfClient setContentFitMode(string mode)

Specifies the mode for fitting the HTML content to the print area by upscaling or downscaling it.

Availability:
API client >= 6.0.0, converter >= 24.04. See versioning.
Parameter:
  • mode - The fitting mode.
    Allowed Values:
    • auto — Automatic mode
    • smart-scaling — Smartscaling to fit more content into the print area.
    • no-scaling — No scaling is performed.
    • viewport-width — The viewport width fits the print area width.
    • content-width — The HTML content width fits the print area width.
    • single-page — The entire HTML content fits the print area of a single page.
    • single-page-ratio — The entire HTML content fits the print area of a single page, maintaining the aspect ratio of the page height and width.
    Default:
    auto

public HtmlToPdfClient setRemoveBlankPages(string pages)

Specifies which blank pages to exclude from the output document.

Availability:
API client >= 5.13.0, converter >= 20.10. See versioning.
Parameter:
  • pages - The empty page behavior.
    Allowed Values:
    • trailing — Trailing blank pages are removed from the document.
    • all — All empty pages are removed from the document.
    • none — No blank page is removed from the document.
    Default:
    trailing

Watermark & Background

public HtmlToPdfClient setPageWatermark(string watermark)

Apply a watermark to each page of the output PDF file. A watermark can be either a PDF or an image. If a multi-page file (PDF or TIFF) is used, the first page is used as the watermark.

Parameter:
  • watermark - The file path to a local file.
    Constraint:
    • The file must exist and not be empty.
Examples:
  • Multi-page PDF for watermarking: setPageWatermark("/home/user/john/watermark.pdf")
  • Transparent PNG overlay: setPageWatermark("/home/user/john/watermark.png")

public HtmlToPdfClient setPageWatermarkUrl(string url)

Load a file from the specified URL and apply the file as a watermark to each page of the output PDF. A watermark can be either a PDF or an image. If a multi-page file (PDF or TIFF) is used, the first page is used as the watermark.

Parameter:
  • url
    Constraint:
    • Supported protocols are http:// and https://.
Examples:
  • Download watermark from server: setPageWatermarkUrl("http://myserver.com/watermark.pdf")
  • Remote logo watermark: setPageWatermarkUrl("http://myserver.com/watermark.png")

public HtmlToPdfClient setMultipageWatermark(string watermark)

Apply each page of a watermark to the corresponding page of the output PDF. A watermark can be either a PDF or an image.

Parameter:
  • watermark - The file path to a local file.
    Constraint:
    • The file must exist and not be empty.
Examples:
  • Multi-page PDF for watermarking: setMultipageWatermark("/home/user/john/watermark.pdf")
  • Transparent PNG overlay: setMultipageWatermark("/home/user/john/watermark.png")

public HtmlToPdfClient setMultipageWatermarkUrl(string url)

Load a file from the specified URL and apply each page of the file as a watermark to the corresponding page of the output PDF. A watermark can be either a PDF or an image.

Parameter:
  • url
    Constraint:
    • Supported protocols are http:// and https://.
Examples:
  • Download watermark from server: setMultipageWatermarkUrl("http://myserver.com/watermark.pdf")
  • Remote logo watermark: setMultipageWatermarkUrl("http://myserver.com/watermark.png")

public HtmlToPdfClient setPageBackground(string background)

Apply a background to each page of the output PDF file. A background can be either a PDF or an image. If a multi-page file (PDF or TIFF) is used, the first page is used as the background.

Parameter:
  • background - The file path to a local file.
    Constraint:
    • The file must exist and not be empty.
Examples:
  • PDF template background: setPageBackground("/home/user/john/background.pdf")
  • Image texture background: setPageBackground("/home/user/john/background.png")

public HtmlToPdfClient setPageBackgroundUrl(string url)

Load a file from the specified URL and apply the file as a background to each page of the output PDF. A background can be either a PDF or an image. If a multi-page file (PDF or TIFF) is used, the first page is used as the background.

Parameter:
  • url
    Constraint:
    • Supported protocols are http:// and https://.
Examples:
  • Download template background: setPageBackgroundUrl("http://myserver.com/background.pdf")
  • Remote background pattern: setPageBackgroundUrl("http://myserver.com/background.png")

public HtmlToPdfClient setMultipageBackground(string background)

Apply each page of a background to the corresponding page of the output PDF. A background can be either a PDF or an image.

Parameter:
  • background - The file path to a local file.
    Constraint:
    • The file must exist and not be empty.
Examples:
  • PDF template background: setMultipageBackground("/home/user/john/background.pdf")
  • Image texture background: setMultipageBackground("/home/user/john/background.png")

public HtmlToPdfClient setMultipageBackgroundUrl(string url)

Load a file from the specified URL and apply each page of the file as a background to the corresponding page of the output PDF. A background can be either a PDF or an image.

Parameter:
  • url
    Constraint:
    • Supported protocols are http:// and https://.
Examples:
  • Download template background: setMultipageBackgroundUrl("http://myserver.com/background.pdf")
  • Remote background pattern: setMultipageBackgroundUrl("http://myserver.com/background.png")

public HtmlToPdfClient setPageBackgroundColor(string color)

The page background color in RGB or RGBA hexadecimal format. The color fills the entire page regardless of the margins.

Parameter:
  • color
    Constraint:
    • The value must be in RRGGBB or RRGGBBAA hexadecimal format.
Examples:
  • red color: setPageBackgroundColor("FF0000")
  • green color: setPageBackgroundColor("00ff00")
  • green color with 50% opacity: setPageBackgroundColor("00ff0080")

General Options

public HtmlToPdfClient setUsePrintMedia(bool value)

Use the print version of the page if available (@media print).

Parameter:
  • value (bool) - Set to true to use the print version of the page.
    Default:
    false

public HtmlToPdfClient setNoBackground(bool value)

Do not print the background graphics.

Parameter:
  • value (bool) - Set to true to disable the background graphics.
    Default:
    false

public HtmlToPdfClient setDisableJavascript(bool value)

Do not execute JavaScript.

Parameter:
  • value (bool) - Set to true to disable JavaScript in web pages.
    Default:
    false

public HtmlToPdfClient setDisableImageLoading(bool value)

Do not load images.

Parameter:
  • value (bool) - Set to true to disable loading of images.
    Default:
    false

public HtmlToPdfClient setDisableRemoteFonts(bool value)

Disable loading fonts from remote sources.

Parameter:
  • value (bool) - Set to true disable loading remote fonts.
    Default:
    false

public HtmlToPdfClient setUseMobileUserAgent(bool value)

Deprecated Replaced with: setConverterUserAgent

Use a mobile user agent.

Availability:
API client >= 5.3.0, converter >= 20.10. See versioning.
Parameter:
  • value (bool) - Set to true to use a mobile user agent.
    Default:
    false

public HtmlToPdfClient setLoadIframes(string iframes)

Specifies how iframes are handled.

Availability:
API client >= 5.0.0, converter >= 20.10. See versioning.
Parameter:
  • iframes
    Allowed Values:
    • all — All iframes are loaded.
    • same-origin — Only iframes with the same origin as the main page are loaded.
    • none — Iframe loading is disabled.
    Default:
    all

public HtmlToPdfClient setBlockAds(bool value)

Try to block ads. Enabling this option can produce smaller output and speed up the conversion.

Parameter:
  • value (bool) - Set to true to block ads in web pages.
    Default:
    false

public HtmlToPdfClient setDefaultEncoding(string encoding)

Set the default HTML content text encoding.

Parameter:
  • encoding - The text encoding of the HTML content.
    Default:
    auto detect
Examples:
  • Set to use Latin-2 encoding: setDefaultEncoding("iso8859-2")
  • Set to use UTF-8 encoding: setDefaultEncoding("utf-8")

public HtmlToPdfClient setLocale(string locale)

Set the locale for the conversion. This may affect the output format of dates, times and numbers.

Availability:
API client >= 5.0.0, converter >= 20.10. See versioning.
Parameter:
  • locale - The locale code according to ISO 639.
    Default:
    en-US
Example:
  • Set to use Japanese locale: setLocale("ja-JP")

public HtmlToPdfClient setHttpAuth(string userName, string password)

Set credentials to access HTTP base authentication protected websites.

Parameters:
  • userName - Set the HTTP authentication user name.
  • password - Set the HTTP authentication password.

public HtmlToPdfClient setCookies(string cookies)

Set HTTP cookies to be included in all requests made by the converter.

Parameter:
  • cookies - The cookie string.
Example:
  • Multiple cookies for authentication: setCookies("session=6d7184b3bf35;token=2710")

public HtmlToPdfClient setVerifySslCertificates(bool value)

Do not allow insecure HTTPS connections.

Parameter:
  • value (bool) - Set to true to enable SSL certificate verification.
    Default:
    false

public HtmlToPdfClient setFailOnMainUrlError(bool failOnError)

Abort the conversion if the main URL HTTP status code is greater than or equal to 400.

Parameter:
  • failOnError (bool) - Set to true to abort the conversion.
    Default:
    false

public HtmlToPdfClient setFailOnAnyUrlError(bool failOnError)

Abort the conversion if any of the sub-request HTTP status code is greater than or equal to 400 or if some sub-requests are still pending. See details in a debug log.

Parameter:
  • failOnError (bool) - Set to true to abort the conversion.
    Default:
    false

public HtmlToPdfClient setNoXpdfcrowdHeader(bool value)

Do not send the X-Pdfcrowd HTTP header in PDFCrowd HTTP requests.

Parameter:
  • value (bool) - Set to true to disable sending X-Pdfcrowd HTTP header.
    Default:
    false

public HtmlToPdfClient setCssPageRuleMode(string mode)

Specifies behavior in presence of CSS @page rules. It may affect the page size, margins and orientation.

Availability:
API client >= 5.0.0, converter >= 20.10. See versioning.
Parameter:
  • mode - The page rule mode.
    Allowed Values:
    • default — The PDFCrowd API page settings are preferred.
    • mode1 — The converter version 18.10 mode.
    • mode2 — CSS @page rule is preferred.
    Default:
    default

public HtmlToPdfClient setCustomCss(string css)

Apply custom CSS to the input HTML document. It allows you to modify the visual appearance and layout of your HTML content dynamically. Tip: Using !important in custom CSS provides a way to prioritize and override conflicting styles.

Availability:
API client >= 5.14.0, converter >= 20.10. See versioning.
Parameter:
  • css - A string containing valid CSS.
Examples:
  • Set the page background color to gray: setCustomCss("body { background-color: gray; }")
  • Do not show nav HTML elements and the element with ad-block ID in the output PDF: setCustomCss("nav, #ad-block { display: none !important; }")

public HtmlToPdfClient setCustomJavascript(string javascript)

Run a custom JavaScript after the document is loaded and ready to print. The script is intended for post-load DOM manipulation (add/remove elements, update CSS, ...). In addition to the standard browser APIs, the custom JavaScript code can use helper functions from our JavaScript library.

Parameter:
  • javascript - A string containing a JavaScript code.
Example:
  • Set the page background color to gray: setCustomJavascript("document.body.style.setProperty('background-color', 'gray', 'important')")

public HtmlToPdfClient setOnLoadJavascript(string javascript)

Run a custom JavaScript right after the document is loaded. The script is intended for early DOM manipulation (add/remove elements, update CSS, ...). In addition to the standard browser APIs, the custom JavaScript code can use helper functions from our JavaScript library.

Parameter:
  • javascript - A string containing a JavaScript code.
Example:
  • Set the page background color to gray: setOnLoadJavascript("document.body.style.setProperty('background-color', 'gray', 'important')")

public HtmlToPdfClient setCustomHttpHeader(string header)

Set a custom HTTP header to be included in all requests made by the converter.

Parameter:
  • header
    Constraint:
    • A string containing the header name and value separated by a colon.
Example:
  • API client tracking header: setCustomHttpHeader("X-My-Client-ID:k2017-12345")

public HtmlToPdfClient setJavascriptDelay(int delay)

Wait the specified number of milliseconds to finish all JavaScript after the document is loaded. Your license defines the maximum wait time by "Max Delay" parameter.

Parameter:
  • delay (int) - The number of milliseconds to wait.
    Constraint:
    • Must be a positive integer or 0.
    Default:
    200
Example:
  • Wait for 2 seconds: setJavascriptDelay(2000)

public HtmlToPdfClient setElementToConvert(string selectors)

Convert only the specified element from the main document and its children. The element is specified by one or more CSS selectors. If the element is not found, the conversion fails. If multiple elements are found, the first one is used.

Parameter:
Examples:
  • The first element with the id main-content is converted: setElementToConvert("#main-content")
  • The first element with the class name main-content is converted: setElementToConvert(".main-content")
  • The first element with the tag name table is converted: setElementToConvert("table")
  • The first element with the tag name table or with the id main-content is converted: setElementToConvert("table, #main-content")
  • The first element <p class="article"> within <div class="user-panel main"> is converted: setElementToConvert("div.user-panel.main p.article")

public HtmlToPdfClient setElementToConvertMode(string mode)

Specify the DOM handling when only a part of the document is converted. This can affect the CSS rules used.

Parameter:
  • mode
    Allowed Values:
    • cut-out — The element and its children are cut out of the document.
    • remove-siblings — All element's siblings are removed.
    • hide-siblings — All element's siblings are hidden.
    Default:
    cut-out

public HtmlToPdfClient setWaitForElement(string selectors)

Wait for the specified element in a source document. The element is specified by one or more CSS selectors. The element is searched for in the main document and all iframes. If the element is not found, the conversion fails. Your license defines the maximum wait time by "Max Delay" parameter.

Parameter:
Examples:
  • Wait until an element with the id main-content is found: setWaitForElement("#main-content")
  • Wait until an element with the class name main-content is found: setWaitForElement(".main-content")
  • Wait until an element with the tag name table is found: setWaitForElement("table")
  • Wait until an element with the tag name table or with the id main-content is found: setWaitForElement("table, #main-content")
  • Wait until <p class="article"> is found within <div class="user-panel main">: setWaitForElement("div.user-panel.main p.article")

public HtmlToPdfClient setAutoDetectElementToConvert(bool value)

The main HTML element for conversion is detected automatically.

Availability:
API client >= 5.5.0, converter >= 20.10. See versioning.
Parameter:
  • value (bool) - Set to true to detect the main element.
    Default:
    false

public HtmlToPdfClient setReadabilityEnhancements(string enhancements)

The input HTML is automatically enhanced to improve the readability.

Availability:
API client >= 5.5.0, converter >= 20.10. See versioning.
Parameter:
  • enhancements
    Allowed Values:
    • none — No enhancements are used.
    • readability-v1 — Version 1 of the enhancements is used.
    • readability-v2 — Version 2 of the enhancements is used.
    • readability-v3 — Version 3 of the enhancements is used.
    • readability-v4 — Version 4 of the enhancements is used.
    Default:
    none

PDF Format

Miscellaneous values for PDF output.

public HtmlToPdfClient setEnablePdfForms(bool value)

Convert HTML forms to fillable PDF forms. Details can be found in the blog post.

Parameter:
  • value (bool) - Set to true to make fillable PDF forms.
    Default:
    false

public HtmlToPdfClient setLinearize(bool value)

Create linearized PDF. This is also known as Fast Web View.

Parameter:
  • value (bool) - Set to true to create linearized PDF.
    Default:
    false

public HtmlToPdfClient setEncrypt(bool value)

Encrypt the PDF. This prevents search engines from indexing the contents.

Parameter:
  • value (bool) - Set to true to enable PDF encryption.
    Default:
    false

public HtmlToPdfClient setUserPassword(string password)

Protect the PDF with a user password. When a PDF has a user password, it must be supplied in order to view the document and to perform operations allowed by the access permissions.

Parameter:
  • password - The user password.
Example:
  • Simple document password: setUserPassword("123456")

public HtmlToPdfClient setOwnerPassword(string password)

Protect the PDF with an owner password. Supplying an owner password grants unlimited access to the PDF including changing the passwords and access permissions.

Parameter:
  • password - The owner password.
Example:
  • Admin access password: setOwnerPassword("123456")

public HtmlToPdfClient setNoPrint(bool value)

Disallow printing of the output PDF.

Parameter:
  • value (bool) - Set to true to set the no-print flag in the output PDF.
    Default:
    false

public HtmlToPdfClient setNoModify(bool value)

Disallow modification of the output PDF.

Parameter:
  • value (bool) - Set to true to set the read-only only flag in the output PDF.
    Default:
    false

public HtmlToPdfClient setNoCopy(bool value)

Disallow text and graphics extraction from the output PDF.

Parameter:
  • value (bool) - Set to true to set the no-copy flag in the output PDF.
    Default:
    false

public HtmlToPdfClient setTitle(string title)

Set the title of the PDF.

Parameter:
  • title - The title.
Example:
  • Personal CV title: setTitle("My Resume")

public HtmlToPdfClient setSubject(string subject)

Set the subject of the PDF.

Parameter:
  • subject - The subject.
Example:
  • Technical position subject: setSubject("CV - Software Developer")

public HtmlToPdfClient setAuthor(string author)

Set the author of the PDF.

Parameter:
  • author - The author.
Example:
  • Document author name: setAuthor("John Doe")

public HtmlToPdfClient setKeywords(string keywords)

Associate keywords with the document.

Parameter:
  • keywords - The string with the keywords.
Example:
  • Technical skills for searchability: setKeywords("software developer, Unix, databases")

public HtmlToPdfClient setExtractMetaTags(bool value)

Extract meta tags (author, keywords and description) from the input HTML and use them in the output PDF.

Parameter:
  • value (bool) - Set to true to extract meta tags.
    Default:
    false

Viewer Preferences

These preferences specify how a PDF viewer should present the document. The preferences may be ignored by some PDF viewers.

public HtmlToPdfClient setPageLayout(string layout)

Specify the page layout to be used when the document is opened.

Parameter:
  • layout
    Allowed Values:
    • single-page — Display one page at a time.
    • one-column — Display the pages in one column.
    • two-column-left — Display the pages in two columns, with odd-numbered pages on the left.
    • two-column-right — Display the pages in two columns, with odd-numbered pages on the right.

public HtmlToPdfClient setPageMode(string mode)

Specify how the document should be displayed when opened.

Parameter:
  • mode
    Allowed Values:
    • full-screen — Full-screen mode.
    • thumbnails — Thumbnail images are visible.
    • outlines — Document outline is visible.

public HtmlToPdfClient setInitialZoomType(string zoomType)

Specify how the page should be displayed when opened.

Parameter:
  • zoomType
    Allowed Values:
    • fit-width — The page content is magnified just enough to fit the entire width of the page within the window.
    • fit-height — The page content is magnified just enough to fit the entire height of the page within the window.
    • fit-page — The page content is magnified just enough to fit the entire page within the window both horizontally and vertically. If the required horizontal and vertical magnification factors are different, use the smaller of the two, centering the page within the window in the other dimension.

public HtmlToPdfClient setInitialPage(int page)

Display the specified page when the document is opened.

Parameter:
  • page (int)
    Constraint:
    • Must be a positive integer.
Example:
  • Start at second page: setInitialPage(2)

public HtmlToPdfClient setInitialZoom(int zoom)

Specify the initial page zoom in percents when the document is opened.

Parameter:
  • zoom (int)
    Constraint:
    • Must be a positive integer.
Example:
  • Half-size zoom level: setInitialZoom(50)

public HtmlToPdfClient setHideToolbar(bool value)

Specify whether to hide the viewer application's tool bars when the document is active.

Parameter:
  • value (bool) - Set to true to hide tool bars.
    Default:
    false

public HtmlToPdfClient setHideMenubar(bool value)

Specify whether to hide the viewer application's menu bar when the document is active.

Parameter:
  • value (bool) - Set to true to hide the menu bar.
    Default:
    false

public HtmlToPdfClient setHideWindowUi(bool value)

Specify whether to hide user interface elements in the document's window (such as scroll bars and navigation controls), leaving only the document's contents displayed.

Parameter:
  • value (bool) - Set to true to hide ui elements.
    Default:
    false

public HtmlToPdfClient setFitWindow(bool value)

Specify whether to resize the document's window to fit the size of the first displayed page.

Parameter:
  • value (bool) - Set to true to resize the window.
    Default:
    false

public HtmlToPdfClient setCenterWindow(bool value)

Specify whether to position the document's window in the center of the screen.

Parameter:
  • value (bool) - Set to true to center the window.
    Default:
    false

public HtmlToPdfClient setDisplayTitle(bool value)

Specify whether the window's title bar should display the document title. If false , the title bar should instead display the name of the PDF file containing the document.

Parameter:
  • value (bool) - Set to true to display the title.
    Default:
    false

public HtmlToPdfClient setRightToLeft(bool value)

Set the predominant reading order for text to right-to-left. This option has no direct effect on the document's contents or page numbering but can be used to determine the relative positioning of pages when displayed side by side or printed n-up

Parameter:
  • value (bool) - Set to true to set right-to-left reading order.
    Default:
    false

Data

Methods related to HTML template rendering.

public HtmlToPdfClient setDataString(string dataString)

Set the input data for template rendering. The data format can be JSON, XML, YAML or CSV.

Parameter:
  • dataString - The input data string.
Example:
  • Template variables for mail merge: setDataString("{"recipient": "Anna May", "sender": "John Doe"}")

public HtmlToPdfClient setDataFile(string dataFile)

Load the input data for template rendering from the specified file. The data format can be JSON, XML, YAML or CSV.

Parameter:
  • dataFile - The file path to a local file containing the input data.
Example:
  • External data for template rendering: setDataFile("/home/user/john/data.json")

public HtmlToPdfClient setDataFormat(string dataFormat)

Specify the input data format.

Parameter:
  • dataFormat - The data format.
    Allowed Values:
    • auto — the data format is auto detected
    • json
    • xml
    • yaml
    • csv
    Default:
    auto

public HtmlToPdfClient setDataEncoding(string encoding)

Set the encoding of the data file set by setDataFile.

Parameter:
  • encoding - The data file encoding.
    Default:
    utf-8
Example:
  • Set to use Latin-2 encoding: setDataEncoding("iso8859-2")

public HtmlToPdfClient setDataIgnoreUndefined(bool value)

Ignore undefined variables in the HTML template. The default mode is strict so any undefined variable causes the conversion to fail. You can use {% if variable is defined %} to check if the variable is defined.

Parameter:
  • value (bool) - Set to true to ignore undefined variables.
    Default:
    false

public HtmlToPdfClient setDataAutoEscape(bool value)

Auto escape HTML symbols in the input data before placing them into the output.

Parameter:
  • value (bool) - Set to true to turn auto escaping on.
    Default:
    false

public HtmlToPdfClient setDataTrimBlocks(bool value)

Auto trim whitespace around each template command block.

Parameter:
  • value (bool) - Set to true to turn auto trimming on.
    Default:
    false

public HtmlToPdfClient setDataOptions(string options)

Set the advanced data options:
  • csv_delimiter - The CSV data delimiter, the default is ,.
  • xml_remove_root - Remove the root XML element from the input data.
  • data_root - The name of the root element inserted into the input data without a root node (e.g. CSV), the default is data.
Parameter:
  • options - Comma separated list of options.
Examples:
  • Use semicolon to separate CSV data: setDataOptions("csv_delimiter=;")
  • Name the root of data rows and use the name in the template loop {% for row in rows %}...{% endfor %}: setDataOptions("data_root=rows")
  • Remove XML root so it the HTML template can be more simple: setDataOptions("xml_remove_root=1")

Miscellaneous

public HtmlToPdfClient setDebugLog(bool value)

Turn on the debug logging. Details about the conversion are stored in the debug log. The URL of the log can be obtained from the getDebugLogUrl method or available in conversion statistics.

Parameter:
  • value (bool) - Set to true to enable the debug logging.
    Default:
    false

public string getDebugLogUrl()

Get the URL of the debug log for the last conversion.

Returns:
string - The link to the debug log.

public int getRemainingCreditCount()

Get the number of conversion credits available in your account.
This method can only be called after a call to one of the convertXtoY methods.
The returned value can differ from the actual count if you run parallel conversions.
The special value 999999 is returned if the information is not available.

Returns:
int - The number of credits.

public int getConsumedCreditCount()

Get the number of credits consumed by the last conversion.

Returns:
int - The number of credits.

public string getJobId()

Get the job id.

Returns:
string - The unique job identifier.

public int getPageCount()

Get the number of pages in the output document.

Returns:
int - The page count.

public int getTotalPageCount()

Get the total number of pages in the original output document, including the pages excluded by setPrintPageRange().

Returns:
int - The total page count.

public int getOutputSize()

Get the size of the output in bytes.

Returns:
int - The count of bytes.

public string getVersion()

Get the version details.

Returns:
string - API version, converter version, and client version.

public HtmlToPdfClient setTag(string tag)

Tag the conversion with a custom value. The tag is used in conversion statistics. A value longer than 32 characters is cut off.

Parameter:
  • tag - A string with the custom tag.
Example:
  • Track job in analytics: setTag("client-1234")

public HtmlToPdfClient setHttpProxy(string proxy)

A proxy server used by the conversion process for accessing the source URLs with HTTP scheme. It can help to circumvent regional restrictions or provide limited access to your intranet.

Parameter:
  • proxy
    Constraint:
    • The value must have format DOMAIN_OR_IP_ADDRESS:PORT.
Examples:
  • Corporate proxy server: setHttpProxy("myproxy.com:8080")
  • Direct IP proxy connection: setHttpProxy("113.25.84.10:33333")

public HtmlToPdfClient setHttpsProxy(string proxy)

A proxy server used by the conversion process for accessing the source URLs with HTTPS scheme. It can help to circumvent regional restrictions or provide limited access to your intranet.

Parameter:
  • proxy
    Constraint:
    • The value must have format DOMAIN_OR_IP_ADDRESS:PORT.
Examples:
  • Secure proxy for HTTPS: setHttpsProxy("myproxy.com:443")
  • Direct secure proxy IP: setHttpsProxy("113.25.84.10:44333")

public HtmlToPdfClient setClientCertificate(string certificate)

A client certificate to authenticate the converter on your web server. The certificate is used for two-way SSL/TLS authentication and adds extra security.

Parameter:
  • certificate - The file must be in PKCS12 format.
    Constraint:
    • The file must exist and not be empty.
Example:
  • Custom CA certificate path: setClientCertificate("/home/user/john/pdfcrowd.crt")

public HtmlToPdfClient setClientCertificatePassword(string password)

A password for PKCS12 file with a client certificate if it is needed.

Parameter:
  • password
Example:
  • PKCS12 certificate password: setClientCertificatePassword("123456")

Tweaks

Expert options for fine-tuning output.

public HtmlToPdfClient setLayoutDpi(int dpi)

Set the internal DPI resolution used for positioning of PDF contents. It can help in situations when there are small inaccuracies in the PDF. It is recommended to use values that are a multiple of 72, such as 288 or 360.

Availability:
API client >= 5.0.0, converter >= 20.10. See versioning.
Parameter:
  • dpi (int) - The DPI value.
    Constraint:
    • The accepted range is 72-600.
    Default:
    300
Example:
  • Low DPI for faster processing: setLayoutDpi(144)

public HtmlToPdfClient setContentAreaX(string x)

Set the top left X coordinate of the content area. It is relative to the top left X coordinate of the print area.

Parameter:
  • x
    Constraint:
    • The value must be specified in inches 'in', millimeters 'mm', centimeters 'cm', pixels 'px', or points 'pt'. It may contain a negative value.
    Default:
    0in
Examples:
  • Extend content beyond left margin: setContentAreaX("-1in")
  • Slight inset from print edge: setContentAreaX("10mm")

public HtmlToPdfClient setContentAreaY(string y)

Set the top left Y coordinate of the content area. It is relative to the top left Y coordinate of the print area.

Parameter:
  • y
    Constraint:
    • The value must be specified in inches 'in', millimeters 'mm', centimeters 'cm', pixels 'px', or points 'pt'. It may contain a negative value.
    Default:
    0in
Examples:
  • Extend content beyond left margin: setContentAreaY("-1in")
  • Slight inset from print edge: setContentAreaY("10mm")

public HtmlToPdfClient setContentAreaWidth(string width)

Set the width of the content area. It should be at least 1 inch.

Parameter:
  • width
    Constraint:
    • The value must be specified in inches 'in', millimeters 'mm', centimeters 'cm', pixels 'px', or points 'pt'.
    Default:
    The width of the print area.
Examples:
  • Content for letter-width viewport: setContentAreaWidth("8in")
  • Content for A4 portrait layout: setContentAreaWidth("210mm")

public HtmlToPdfClient setContentAreaHeight(string height)

Set the height of the content area. It should be at least 1 inch.

Parameter:
  • height
    Constraint:
    • The value must be specified in inches 'in', millimeters 'mm', centimeters 'cm', pixels 'px', or points 'pt'.
    Default:
    The height of the print area.
Examples:
  • Content for letter-width viewport: setContentAreaHeight("8in")
  • Content for A4 portrait layout: setContentAreaHeight("210mm")

public HtmlToPdfClient setContentArea(string x, string y, string width, string height)

Set the content area position and size. The content area enables to specify a web page area to be converted.

Parameters:
  • x - Set the top left X coordinate of the content area. It is relative to the top left X coordinate of the print area.
    Constraint:
    • The value must be specified in inches 'in', millimeters 'mm', centimeters 'cm', pixels 'px', 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.
    Constraint:
    • The value must be specified in inches 'in', millimeters 'mm', centimeters 'cm', pixels 'px', 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.
    Constraint:
    • The value must be specified in inches 'in', millimeters 'mm', centimeters 'cm', pixels 'px', 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.
    Constraint:
    • The value must be specified in inches 'in', millimeters 'mm', centimeters 'cm', pixels 'px', or points 'pt'.
    Default:
    The height of the print area.

public HtmlToPdfClient setContentsMatrix(string matrix)

A 2D transformation matrix applied to the main contents on each page. The origin [0,0] is located at the top-left corner of the contents. The resolution is 72 dpi.

Availability:
API client >= 5.0.0, converter >= 20.10. See versioning.
Parameter:
  • matrix - A comma separated string of matrix elements: "scaleX,skewX,transX,skewY,scaleY,transY"
    Default:
    1,0,0,0,1,0
Examples:
  • Fine tune the contents height: setContentsMatrix("1,0,0,0,1.001,0")
  • Translate the contents by -10 points in both directions: setContentsMatrix("1,0,-10,0,1,-10")

public HtmlToPdfClient setHeaderMatrix(string matrix)

A 2D transformation matrix applied to the page header contents. The origin [0,0] is located at the top-left corner of the header. The resolution is 72 dpi.

Availability:
API client >= 5.0.0, converter >= 20.10. See versioning.
Parameter:
  • matrix - A comma separated string of matrix elements: "scaleX,skewX,transX,skewY,scaleY,transY"
    Default:
    1,0,0,0,1,0
Examples:
  • Fine tune the header contents height: setHeaderMatrix("1,0,0,0,1.001,0")
  • Translate the header contents by -10 points in both directions: setHeaderMatrix("1,0,-10,0,1,-10")

public HtmlToPdfClient setDisablePageHeightOptimization(bool value)

Disable automatic height adjustment that compensates for pixel to point rounding errors.

Availability:
API client >= 5.0.0, converter >= 20.10. See versioning.
Parameter:
  • value (bool) - Set to true to disable automatic height scale.
    Default:
    false

public HtmlToPdfClient setMainDocumentCssAnnotation(bool value)

Add special CSS classes to the main document's body element. This allows applying custom styling based on these classes:
  • pdfcrowd-page-X - where X is the current page number
  • pdfcrowd-page-odd - odd page
  • pdfcrowd-page-even - even page
Availability:
API client >= 5.0.0, converter >= 20.10. See versioning.
Parameter:
  • value (bool) - Set to true to add the special CSS classes.
    Default:
    false
Example:

public HtmlToPdfClient setMaxLoadingTime(int maxTime)

Set the maximum time to load the page and its resources. After this time, all requests will be considered successful. This can be useful to ensure that the conversion does not timeout. Use this method if there is no other way to fix page loading.

Availability:
API client >= 5.15.0, converter >= 20.10. See versioning.
Parameter:
  • maxTime (int) - The number of seconds to wait.
    Constraint:
    • The accepted range is 10-30.

public HtmlToPdfClient setConversionConfig(string jsonString)

Allows to configure conversion via JSON. The configuration defines various page settings for individual PDF pages or ranges of pages. It provides flexibility in designing each page of the PDF, giving control over each page's size, header, footer etc. If a page or parameter is not explicitly specified, the system will use the default settings for that page or attribute. If a JSON configuration is provided, the settings in the JSON will take precedence over the global options.

The structure of the JSON must be:

  • pageSetup: An array of objects where each object defines the configuration for a specific page or range of pages. The following properties can be set for each page object:
    • pages: A comma-separated list of page numbers or ranges. Special strings may be used, such as `odd`, `even` and `last`. For example:
      • 1-: from page 1 to the end of the document
      • 2: only the 2nd page
      • 2,4,6: pages 2, 4, and 6
      • 2-5: pages 2 through 5
      • odd,2: the 2nd page and all odd pages
    • pageSize: The page size (optional). Possible values: A0, A1, A2, A3, A4, A5, A6, Letter.
    • pageWidth: The width of the page (optional).
    • pageHeight: The height of the page (optional).
    • marginLeft: Left margin (optional).
    • marginRight: Right margin (optional).
    • marginTop: Top margin (optional).
    • marginBottom: Bottom margin (optional).
    • displayHeader: Header appearance (optional). Possible values:
      • none: completely excluded
      • space: only the content is excluded, the space is used
      • content: the content is printed (default)
    • displayFooter: Footer appearance (optional). Possible values:
      • none: completely excluded
      • space: only the content is excluded, the space is used
      • content: the content is printed (default)
    • headerHeight: Height of the header (optional).
    • footerHeight: Height of the footer (optional).
    • orientation: Page orientation, such as "portrait" or "landscape" (optional).
    • backgroundColor: Page background color in RRGGBB or RRGGBBAA hexadecimal format (optional).

Dimensions may be empty, 0 or specified in inches 'in', millimeters 'mm', centimeters 'cm', pixels 'px', or points 'pt'.

Availability:
API client >= 6.1.0, converter >= 24.04. See versioning.
Parameter:
  • jsonString - The JSON string.
Examples:
  • Modify the margins and orientation, and hide the header and footer on some pages.
    {
      "pageSetup": [
        {
          "pages": "1,3",
          "marginLeft": "72pt",
          "marginRight": "72pt",
          "marginTop": "72pt",
          "marginBottom": "72pt",
          "displayHeader": "content",
          "displayFooter": "none"
        },
        {
          "pages": "2-5",
          "orientation": "landscape",
          "marginTop": "0",
          "marginBottom": "0",
          "headerHeight": "1cm",
          "displayHeader": "content",
          "displayFooter": "none"
        },
        {
          "pages": "10",
          "pageWidth": "6in",
          "pageHeight": "10in",
          "displayHeader": "none",
          "displayFooter": "content"
        },
        {
          "pages": "last",
          "backgroundColor": "00ff0080"
        }
      ]
    }
    
  • A header is placed only on the first page, and a footer only on the last page. No space is occupied on other pages.
    {
      "pageSetup": [
        {
          "pages": "1-",
          "displayHeader": "none",
          "displayFooter": "none"
        },
        {
          "pages": "1",
          "displayHeader": "content"
        },
        {
          "pages": "last",
          "displayFooter": "content"
        }
      ]
    }
    

public HtmlToPdfClient setConversionConfigFile(string filepath)

Allows to configure the conversion process via JSON file. See details of the JSON string.

Availability:
API client >= 6.1.0, converter >= 24.04. See versioning.
Parameter:
  • filepath - The file path to a local file.
    Constraint:
    • The file must exist and not be empty.
Examples:
  • External conversion settings: setConversionConfigFile("/home/user/john/conv_config.json")
  • see example of the JSON string

public HtmlToPdfClient setConverterUserAgent(string agent)

Specifies the User-Agent HTTP header that will be used by the converter when a request is made to the converted web page.

Availability:
API client >= 6.4.0 See versioning.
Parameter:
  • agent - The user agent.
    Allowed Values:
    • chrome-desktop — The user-agent for desktop chrome corresponding to the converter used.
    • chrome-mobile — The user-agent for mobile chrome corresponding to the converter used.
    • latest-chrome-desktop — The user-agent of the recently released Chrome browser on desktops.
    • latest-chrome-mobile — The user-agent of the recently released Chrome browser on mobile devices.
    • custom string — A custom string for the user agent.
    Default:
    latest-chrome-desktop
Examples:
  • Mimic the recent chrome on mobiles: setConverterUserAgent("latest-chrome-mobile")
  • Mimic Safari 18.0 browser: setConverterUserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 14_7_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.0 Safari/605.1.15")

API Client Options

public HtmlToPdfClient setConverterVersion(string version)

Set the converter version. Different versions may produce different output. Choose which one provides the best output for your case.

Availability:
API client >= 5.0.0. See versioning.
Parameter:
  • version - The version identifier.
    Allowed Values:
    • 24.04 — Version 24.04.
    • 20.10 — Version 20.10.
    • 18.10 — Version 18.10.
    • latest — Version 20.10 is used.
    Default:
    24.04

public HtmlToPdfClient setUseHttp(bool value)

Specify whether to use HTTP or HTTPS when connecting to the PDFCrowd API.

Parameter:
  • value (bool) - Set to true to use HTTP.
    Default:
    false

public HtmlToPdfClient setClientUserAgent(string agent)

Specifies the User-Agent HTTP header that the client library will use when interacting with the API.

Availability:
API client >= 6.4.0 See versioning.
Parameter:
  • agent - The user agent string.

public HtmlToPdfClient setUserAgent(string agent)

Deprecated Replaced with: setClientUserAgent

Set a custom user agent HTTP header. It can be useful if you are behind a proxy or a firewall.

Parameter:
  • agent - The user agent string.
    Default:
    pdfcrowd_dotnet_client/6.5.2 (https://pdfcrowd.com)

public HtmlToPdfClient setProxy(string host, int port, string userName, string password)

Specifies an HTTP proxy that the API client library will use to connect to the internet.

Parameters:
  • host - The proxy hostname.
  • port (int) - The proxy port.
  • userName - The username.
  • password - The password.

public HtmlToPdfClient setRetryCount(int count)

Specifies the number of automatic retries when the 502 or 503 HTTP status code is received. The status code indicates a temporary network issue. This feature can be disabled by setting to 0.

Parameter:
  • count (int) - Number of retries.
    Default:
    1
Example:
  • Retry failed requests three times: setRetryCount(3)