HTML to Image API - Go

Convert web pages and HTML documents to various image formats in Go using the Pdfcrowd API v2. The API is easy to use and the integration takes only a couple of lines of code.

Installation

Install the client library from Github
go get github.com/pdfcrowd/pdfcrowd-go

Learn more about other install options.

Authentication

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

Examples

package main

import (
    "os"
    "fmt"
    "github.com/pdfcrowd/pdfcrowd-go"
)

func main() {
    // create the API client instance
    client := pdfcrowd.NewHtmlToImageClient("your_username", "your_apikey")

    // configure the conversion
    client.SetOutputFormat("png")

    // run the conversion and write the result to a file
    err := client.ConvertUrlToFile("http://www.example.com", "example.png")

    // check for a conversion error
    handleError(err)
}

func handleError(err error) {
    if err != nil {
        // report the error
        why, ok := err.(pdfcrowd.Error)
        if ok {
            os.Stderr.WriteString(fmt.Sprintf("Pdfcrowd Error: %s\n", why))
        } else {
            os.Stderr.WriteString(fmt.Sprintf("Generic Error: %s\n", err))
        }

        // handle the exception here or rethrow and handle it at a higher level
        panic(err.Error())
    }
}
package main

import (
    "os"
    "fmt"
    "github.com/pdfcrowd/pdfcrowd-go"
)

func main() {
    // create the API client instance
    client := pdfcrowd.NewHtmlToImageClient("your_username", "your_apikey")

    // configure the conversion
    client.SetOutputFormat("png")

    // create output file for conversion result
    outputFile, err := os.Create("example.png")

    // check for a file creation error
    handleError(err)

    // close the output file
    defer outputFile.Close()

    // run the conversion and store the result into an image variable
    image, err := client.ConvertUrl("http://www.example.com")

    // check for a conversion error
    handleError(err)

    // write the image into the output file
    _, err = outputFile.Write(image)

    // check for a file write error
    handleError(err)
}

func handleError(err error) {
    if err != nil {
        // report the error
        why, ok := err.(pdfcrowd.Error)
        if ok {
            os.Stderr.WriteString(fmt.Sprintf("Pdfcrowd Error: %s\n", why))
        } else {
            os.Stderr.WriteString(fmt.Sprintf("Generic Error: %s\n", err))
        }

        // handle the exception here or rethrow and handle it at a higher level
        panic(err.Error())
    }
}
package main

import (
    "os"
    "fmt"
    "github.com/pdfcrowd/pdfcrowd-go"
)

func main() {
    // create the API client instance
    client := pdfcrowd.NewHtmlToImageClient("your_username", "your_apikey")

    // configure the conversion
    client.SetOutputFormat("png")

    // create output stream for conversion result
    outputStream, err := os.Create("example.png")

    // check for a file creation error
    handleError(err)

    // close the output stream
    defer outputStream.Close()

    // run the conversion and write the result into the output stream
    err = client.ConvertUrlToStream("http://www.example.com", outputStream)

    // check for a conversion error
    handleError(err)
}

func handleError(err error) {
    if err != nil {
        // report the error
        why, ok := err.(pdfcrowd.Error)
        if ok {
            os.Stderr.WriteString(fmt.Sprintf("Pdfcrowd Error: %s\n", why))
        } else {
            os.Stderr.WriteString(fmt.Sprintf("Generic Error: %s\n", err))
        }

        // handle the exception here or rethrow and handle it at a higher level
        panic(err.Error())
    }
}
package main

import (
    "os"
    "fmt"
    "github.com/pdfcrowd/pdfcrowd-go"
)

func main() {
    // create the API client instance
    client := pdfcrowd.NewHtmlToImageClient("your_username", "your_apikey")

    // configure the conversion
    client.SetOutputFormat("png")

    // run the conversion and write the result to a file
    err := client.ConvertFileToFile("/path/to/MyLayout.html", "MyLayout.png")

    // check for a conversion error
    handleError(err)
}

func handleError(err error) {
    if err != nil {
        // report the error
        why, ok := err.(pdfcrowd.Error)
        if ok {
            os.Stderr.WriteString(fmt.Sprintf("Pdfcrowd Error: %s\n", why))
        } else {
            os.Stderr.WriteString(fmt.Sprintf("Generic Error: %s\n", err))
        }

        // handle the exception here or rethrow and handle it at a higher level
        panic(err.Error())
    }
}
package main

import (
    "os"
    "fmt"
    "github.com/pdfcrowd/pdfcrowd-go"
)

func main() {
    // create the API client instance
    client := pdfcrowd.NewHtmlToImageClient("your_username", "your_apikey")

    // configure the conversion
    client.SetOutputFormat("png")

    // create output file for conversion result
    outputFile, err := os.Create("MyLayout.png")

    // check for a file creation error
    handleError(err)

    // close the output file
    defer outputFile.Close()

    // run the conversion and store the result into an image variable
    image, err := client.ConvertFile("/path/to/MyLayout.html")

    // check for a conversion error
    handleError(err)

    // write the image into the output file
    _, err = outputFile.Write(image)

    // check for a file write error
    handleError(err)
}

func handleError(err error) {
    if err != nil {
        // report the error
        why, ok := err.(pdfcrowd.Error)
        if ok {
            os.Stderr.WriteString(fmt.Sprintf("Pdfcrowd Error: %s\n", why))
        } else {
            os.Stderr.WriteString(fmt.Sprintf("Generic Error: %s\n", err))
        }

        // handle the exception here or rethrow and handle it at a higher level
        panic(err.Error())
    }
}
package main

import (
    "os"
    "fmt"
    "github.com/pdfcrowd/pdfcrowd-go"
)

func main() {
    // create the API client instance
    client := pdfcrowd.NewHtmlToImageClient("your_username", "your_apikey")

    // configure the conversion
    client.SetOutputFormat("png")

    // create output stream for conversion result
    outputStream, err := os.Create("MyLayout.png")

    // check for a file creation error
    handleError(err)

    // close the output stream
    defer outputStream.Close()

    // run the conversion and write the result into the output stream
    err = client.ConvertFileToStream("/path/to/MyLayout.html", outputStream)

    // check for a conversion error
    handleError(err)
}

func handleError(err error) {
    if err != nil {
        // report the error
        why, ok := err.(pdfcrowd.Error)
        if ok {
            os.Stderr.WriteString(fmt.Sprintf("Pdfcrowd Error: %s\n", why))
        } else {
            os.Stderr.WriteString(fmt.Sprintf("Generic Error: %s\n", err))
        }

        // handle the exception here or rethrow and handle it at a higher level
        panic(err.Error())
    }
}
package main

import (
    "os"
    "fmt"
    "github.com/pdfcrowd/pdfcrowd-go"
)

func main() {
    // create the API client instance
    client := pdfcrowd.NewHtmlToImageClient("your_username", "your_apikey")

    // configure the conversion
    client.SetOutputFormat("png")

    // run the conversion and write the result to a file
    err := client.ConvertStringToFile("<html><body><h1>Hello World!</h1></body></html>", "HelloWorld.png")

    // check for a conversion error
    handleError(err)
}

func handleError(err error) {
    if err != nil {
        // report the error
        why, ok := err.(pdfcrowd.Error)
        if ok {
            os.Stderr.WriteString(fmt.Sprintf("Pdfcrowd Error: %s\n", why))
        } else {
            os.Stderr.WriteString(fmt.Sprintf("Generic Error: %s\n", err))
        }

        // handle the exception here or rethrow and handle it at a higher level
        panic(err.Error())
    }
}
package main

import (
    "os"
    "fmt"
    "github.com/pdfcrowd/pdfcrowd-go"
)

func main() {
    // create the API client instance
    client := pdfcrowd.NewHtmlToImageClient("your_username", "your_apikey")

    // configure the conversion
    client.SetOutputFormat("png")

    // create output file for conversion result
    outputFile, err := os.Create("HelloWorld.png")

    // check for a file creation error
    handleError(err)

    // close the output file
    defer outputFile.Close()

    // run the conversion and store the result into an image variable
    image, err := client.ConvertString("<html><body><h1>Hello World!</h1></body></html>")

    // check for a conversion error
    handleError(err)

    // write the image into the output file
    _, err = outputFile.Write(image)

    // check for a file write error
    handleError(err)
}

func handleError(err error) {
    if err != nil {
        // report the error
        why, ok := err.(pdfcrowd.Error)
        if ok {
            os.Stderr.WriteString(fmt.Sprintf("Pdfcrowd Error: %s\n", why))
        } else {
            os.Stderr.WriteString(fmt.Sprintf("Generic Error: %s\n", err))
        }

        // handle the exception here or rethrow and handle it at a higher level
        panic(err.Error())
    }
}
package main

import (
    "os"
    "fmt"
    "github.com/pdfcrowd/pdfcrowd-go"
)

func main() {
    // create the API client instance
    client := pdfcrowd.NewHtmlToImageClient("your_username", "your_apikey")

    // configure the conversion
    client.SetOutputFormat("png")

    // create output stream for conversion result
    outputStream, err := os.Create("HelloWorld.png")

    // check for a file creation error
    handleError(err)

    // close the output stream
    defer outputStream.Close()

    // run the conversion and write the result into the output stream
    err = client.ConvertStringToStream("<html><body><h1>Hello World!</h1></body></html>", outputStream)

    // check for a conversion error
    handleError(err)
}

func handleError(err error) {
    if err != nil {
        // report the error
        why, ok := err.(pdfcrowd.Error)
        if ok {
            os.Stderr.WriteString(fmt.Sprintf("Pdfcrowd Error: %s\n", why))
        } else {
            os.Stderr.WriteString(fmt.Sprintf("Generic Error: %s\n", err))
        }

        // handle the exception here or rethrow and handle it at a higher level
        panic(err.Error())
    }
}
package main

import (
    "os"
    "fmt"
    "github.com/pdfcrowd/pdfcrowd-go"
)

func main() {
    // create the API client instance
    client := pdfcrowd.NewHtmlToImageClient("your_username", "your_apikey")

    // configure the conversion
    client.SetOutputFormat("png")
    client.SetDebugLog(true)

    // run the conversion and write the result to a file
    err := client.ConvertFileToFile("/path/to/MyLayout.html", "MyLayout.png")

    // check for a conversion error
    handleError(err)
    
    // print URL to the debug log
    fmt.Println("Debug log url:", client.GetDebugLogUrl())
    
    // print the number of available conversion credits in your account
    fmt.Println("Remaining credit count:", client.GetRemainingCreditCount())
    
    // print the number of credits consumed by the conversion
    fmt.Println("Consumed credit count:", client.GetConsumedCreditCount())
    
    // print the unique ID of the conversion
    fmt.Println("Job id:", client.GetJobId())
    
    // print the size of the output in bytes
    fmt.Println("Output size:", client.GetOutputSize())
}

func handleError(err error) {
    if err != nil {
        // report the error
        why, ok := err.(pdfcrowd.Error)
        if ok {
            os.Stderr.WriteString(fmt.Sprintf("Pdfcrowd Error: %s\n", why))
        } else {
            os.Stderr.WriteString(fmt.Sprintf("Generic Error: %s\n", err))
        }

        // handle the exception here or rethrow and handle it at a higher level
        panic(err.Error())
    }
}

Tips & Tricks

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:

You can also use these HTML related features:

  • You can use the following classes in your HTML code which hide/remove elements from the output:
    • pdfcrowd-remove - sets display:none!important on the element
    • pdfcrowd-hide - sets visibility:hidden!important on the element
  • You can switch to the print version of the page (if it exists) with SetUsePrintMedia.
  • You can use SetCustomJavascript to alter the HTML contents with a custom JavaScript.

Error Handling

// call the API 

    // print error
    os.Stderr.WriteString(fmt.Sprintf("Pdfcrowd Error: %s\n", why))

    // print just error code
    os.Stderr.WriteString(fmt.Sprintf("Pdfcrowd Error Code: %v\n", why.getCode()))

    // print just error message
    os.Stderr.WriteString(fmt.Sprintf("Pdfcrowd Error Message: %v\n", why.getMessage()))

    // or handle the error in your way

Troubleshooting

  • Check API Status Codes in case of the error code is returned.
  • You can use SetDebugLog and GetDebugLogUrl to get detailed info about the conversion, such as conversion errors, time, console output.
  • You can use our JavaScript library to resolve rendering problems, such as missing content or blank pages.
    Just use SetCustomJavascript with libPdfcrowd.highlightHtml(borders, backgrounds, labels, noZeroSpace) method call to visualize all HTML elements. See example.
  • Take a look at the FAQ section.

API Reference - class HtmlToImageClient

Conversion from HTML to image. All setter methods return HtmlToImageClient object unless otherwise specified.

Constructor

func NewHtmlToImageClient(userName string, apiKey string) HtmlToImageClient
Constructor for the Pdfcrowd API client.
Parameter Description Default
userName
Your username at Pdfcrowd.
apiKey
Your API key.

 

Conversion Format

func (client *HtmlToImageClient) SetOutputFormat(outputFormat string) *HtmlToImageClient
The format of the output file.
Parameter Description Default
outputFormat
Allowed values:
  • png
  • jpg
  • gif
  • tiff
  • bmp
  • ico
  • ppm
  • pgm
  • pbm
  • pnm
  • psb
  • pct
  • ras
  • tga
  • sgi
  • sun
  • webp
png

 

Conversion Input

func (client *HtmlToImageClient) ConvertUrl(url string) ([]byte, error)
Convert a web page.
Parameter Description Default
url
The address of the web page to convert.
The supported protocols are http:// and https://.
Returns
  • []byte - Byte array containing the conversion output.
func (client *HtmlToImageClient) ConvertUrlToStream(url string, outStream io.Writer) error
Convert a web page and write the result to an output stream.
Parameter Description Default
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.
func (client *HtmlToImageClient) ConvertUrlToFile(url string, filePath string) error
Convert a web page and write the result to a local file.
Parameter Description Default
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.
func (client *HtmlToImageClient) ConvertFile(file string) ([]byte, error)
Convert a local file.
Parameter Description Default
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.
Returns
  • []byte - Byte array containing the conversion output.
func (client *HtmlToImageClient) ConvertFileToStream(file string, outStream io.Writer) error
Convert a local file and write the result to an output stream.
Parameter Description Default
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.
func (client *HtmlToImageClient) ConvertFileToFile(file string, filePath string) error
Convert a local file and write the result to a local file.
Parameter Description Default
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.
func (client *HtmlToImageClient) ConvertString(text string) ([]byte, error)
Convert a string.
Parameter Description Default
text
The string content to convert.
The string must not be empty.
Returns
  • []byte - Byte array containing the conversion output.
func (client *HtmlToImageClient) ConvertStringToStream(text string, outStream io.Writer) error
Convert a string and write the output to an output stream.
Parameter Description Default
text
The string content to convert.
The string must not be empty.
outStream
The output stream that will contain the conversion output.
func (client *HtmlToImageClient) ConvertStringToFile(text string, filePath string) error
Convert a string and write the output to a file.
Parameter Description Default
text
The string content to convert.
The string must not be empty.
filePath
The output file path.
The string must not be empty.

 

General Options

func (client *HtmlToImageClient) SetNoBackground(noBackground bool) *HtmlToImageClient
Do not print the background graphics.
Parameter Description Default
noBackground
Set to true to disable the background graphics.
false
func (client *HtmlToImageClient) SetDisableJavascript(disableJavascript bool) *HtmlToImageClient
Do not execute JavaScript.
Parameter Description Default
disableJavascript
Set to true to disable JavaScript in web pages.
false
func (client *HtmlToImageClient) SetDisableImageLoading(disableImageLoading bool) *HtmlToImageClient
Do not load images.
Parameter Description Default
disableImageLoading
Set to true to disable loading of images.
false
func (client *HtmlToImageClient) SetDisableRemoteFonts(disableRemoteFonts bool) *HtmlToImageClient
Disable loading fonts from remote sources.
Parameter Description Default
disableRemoteFonts
Set to true disable loading remote fonts.
false
func (client *HtmlToImageClient) SetBlockAds(blockAds bool) *HtmlToImageClient
Try to block ads. Enabling this option can produce smaller output and speed up the conversion.
Parameter Description Default
blockAds
Set to true to block ads in web pages.
false
func (client *HtmlToImageClient) SetDefaultEncoding(defaultEncoding string) *HtmlToImageClient
Set the default HTML content text encoding.
Parameter Description Default
defaultEncoding
The text encoding of the HTML content.
auto detect
func (client *HtmlToImageClient) SetHttpAuth(userName string, password string) *HtmlToImageClient
Set credentials to access HTTP base authentication protected websites.
Parameter Description Default
userName
Set the HTTP authentication user name.
password
Set the HTTP authentication password.
func (client *HtmlToImageClient) SetUsePrintMedia(usePrintMedia bool) *HtmlToImageClient
Use the print version of the page if available (@media print).
Parameter Description Default
usePrintMedia
Set to true to use the print version of the page.
false
func (client *HtmlToImageClient) SetNoXpdfcrowdHeader(noXpdfcrowdHeader bool) *HtmlToImageClient
Do not send the X-Pdfcrowd HTTP header in Pdfcrowd HTTP requests.
Parameter Description Default
noXpdfcrowdHeader
Set to true to disable sending X-Pdfcrowd HTTP header.
false
func (client *HtmlToImageClient) SetCookies(cookies string) *HtmlToImageClient
Set cookies that are sent in Pdfcrowd HTTP requests.
Parameter Description Default
cookies
The cookie string.
Examples:
  • SetCookies("session=6d7184b3bf35;token=2710")
func (client *HtmlToImageClient) SetVerifySslCertificates(verifySslCertificates bool) *HtmlToImageClient
Do not allow insecure HTTPS connections.
Parameter Description Default
verifySslCertificates
Set to true to enable SSL certificate verification.
false
func (client *HtmlToImageClient) SetFailOnMainUrlError(failOnError bool) *HtmlToImageClient
Abort the conversion if the main URL HTTP status code is greater than or equal to 400.
Parameter Description Default
failOnError
Set to true to abort the conversion.
false
func (client *HtmlToImageClient) SetFailOnAnyUrlError(failOnError bool) *HtmlToImageClient
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 Description Default
failOnError
Set to true to abort the conversion.
false
func (client *HtmlToImageClient) SetCustomJavascript(customJavascript string) *HtmlToImageClient
Run a custom JavaScript after the document is loaded. The script is intended for post-load DOM manipulation (add/remove elements, update CSS, ...).
Parameter Description Default
customJavascript
String containing a JavaScript code.
The string must not be empty.
func (client *HtmlToImageClient) SetCustomHttpHeader(customHttpHeader string) *HtmlToImageClient
Set a custom HTTP header that is sent in Pdfcrowd HTTP requests.
Parameter Description Default
customHttpHeader
A string containing the header name and value separated by a colon.
Examples:
  • SetCustomHttpHeader("X-My-Client-ID:k2017-12345")
func (client *HtmlToImageClient) SetJavascriptDelay(javascriptDelay int) *HtmlToImageClient
Wait the specified number of milliseconds to finish all JavaScript after the document is loaded. The maximum value is determined by your API license.
Parameter Description Default
javascriptDelay
The number of milliseconds to wait.
Must be a positive integer number or 0.
200
func (client *HtmlToImageClient) SetElementToConvert(selectors string) *HtmlToImageClient
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 Description Default
selectors
One or more CSS selectors separated by commas.
The string must not be empty.
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")
func (client *HtmlToImageClient) SetElementToConvertMode(mode string) *HtmlToImageClient
Specify the DOM handling when only a part of the document is converted.
Parameter Description Default
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 sibilings are hidden.
cut-out
func (client *HtmlToImageClient) SetWaitForElement(selectors string) *HtmlToImageClient
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 API license defines the maximum wait time by "Max Delay" parameter.
Parameter Description Default
selectors
One or more CSS selectors separated by commas.
The string must not be empty.
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")

 

Image Output

func (client *HtmlToImageClient) SetScreenshotWidth(screenshotWidth int) *HtmlToImageClient
Set the output image width in pixels.
Parameter Description Default
screenshotWidth
The value must be in a range 96-7680.
1024
func (client *HtmlToImageClient) SetScreenshotHeight(screenshotHeight int) *HtmlToImageClient
Set the output image height in pixels. If it's not specified, actual document height is used.
Parameter Description Default
screenshotHeight
Must be a positive integer number.

 

Miscellaneous

func (client *HtmlToImageClient) SetDebugLog(debugLog bool) *HtmlToImageClient
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 Description Default
debugLog
Set to true to enable the debug logging.
false
func (client *HtmlToImageClient) GetDebugLogUrl() string
Get the URL of the debug log for the last conversion.
Returns
  • string - The link to the debug log.
func (client *HtmlToImageClient) GetRemainingCreditCount() int
Get the number of conversion credits available in your account.
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.
func (client *HtmlToImageClient) GetConsumedCreditCount() int
Get the number of credits consumed by the last conversion.
Returns
  • int - The number of credits.
func (client *HtmlToImageClient) GetJobId() string
Get the job id.
Returns
  • string - The unique job identifier.
func (client *HtmlToImageClient) GetOutputSize() int
Get the size of the output in bytes.
Returns
  • int - The count of bytes.
func (client *HtmlToImageClient) SetTag(tag string) *HtmlToImageClient
Tag the conversion with a custom value. The tag is used in conversion statistics. A value longer than 32 characters is cut off.
Parameter Description Default
tag
A string with the custom tag.
func (client *HtmlToImageClient) SetHttpProxy(httpProxy string) *HtmlToImageClient
A proxy server used by Pdfcrowd 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 Description Default
httpProxy
The value must have format DOMAIN_OR_IP_ADDRESS:PORT.
Examples:
  • SetHttpProxy("myproxy.com:8080")
  • SetHttpProxy("113.25.84.10:33333")
func (client *HtmlToImageClient) SetHttpsProxy(httpsProxy string) *HtmlToImageClient
A proxy server used by Pdfcrowd 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 Description Default
httpsProxy
The value must have format DOMAIN_OR_IP_ADDRESS:PORT.
Examples:
  • SetHttpsProxy("myproxy.com:443")
  • SetHttpsProxy("113.25.84.10:44333")
func (client *HtmlToImageClient) SetClientCertificate(clientCertificate string) *HtmlToImageClient
A client certificate to authenticate Pdfcrowd converter on your web server. The certificate is used for two-way SSL/TLS authentication and adds extra security.
Parameter Description Default
clientCertificate
The file must be in PKCS12 format.
The file must exist and not be empty.
func (client *HtmlToImageClient) SetClientCertificatePassword(clientCertificatePassword string) *HtmlToImageClient
A password for PKCS12 file with a client certificate if it's needed.
Parameter Description Default
clientCertificatePassword

 

API Client Options

func (client *HtmlToImageClient) SetUseHttp(useHttp bool) *HtmlToImageClient
Specifies if the client communicates over HTTP or HTTPS with Pdfcrowd API.
Parameter Description Default
useHttp
Set to true to use HTTP.
false
func (client *HtmlToImageClient) SetUserAgent(userAgent string) *HtmlToImageClient
Set a custom user agent HTTP header. It can be usefull if you are behind some proxy or firewall.
Parameter Description Default
userAgent
The user agent string.
pdfcrowd_go_client/4.4.1 (http://pdfcrowd.com)
func (client *HtmlToImageClient) SetProxy(host string, port int, userName string, password string) *HtmlToImageClient
Specifies an HTTP proxy that the API client library will use to connect to the internet.
Parameter Description Default
host
The proxy hostname.
port
The proxy port.
userName
The username.
password
The password.
func (client *HtmlToImageClient) SetRetryCount(retryCount int) *HtmlToImageClient
Specifies the number of retries when the 502 HTTP status code is received. The 502 status code indicates a temporary network issue. This feature can be disabled by setting to 0.
Parameter Description Default
retryCount
Number of retries wanted.
1