> ## Documentation Index
> Fetch the complete documentation index at: https://jigsaw-13.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# HTML To Any

> Capture screenshots of a website, convert HTML to both image and PDF formats.

## Request Parameters

### Body

**html** `string`

The HTML content to convert to image or PDF. Either `html` or `url` is required, but not both.

**url** `string`

The URL of the webpage to capture. Either `html` or `url` is required, but not both.

**type** `string` (default: png)

The output file format. Supported formats:

<ul>
  <li>`png` - PNG image format</li>
  <li>`jpeg` - JPEG image format</li>
  <li>`webp` - WebP image format</li>
  <li>`pdf` - PDF document</li>
</ul>

**quality** `number` (default: 75)

The quality of the output image (1-100). Higher values produce better quality but larger file sizes. Only applies to jpeg and webp formats.

**full\_page** `boolean` (default: false)

When set to true, captures the entire scrollable area of the page instead of just the viewport.

**omit\_background** `boolean` (default: false)

When set to true, makes the background transparent for PNG format images.

**width** `number` (default: 1920)

The width of the viewport in pixels.

**height** `number` (default: 1080)

The height of the viewport in pixels.

**scale** `number` (default: 1)

Device scale factor (minimum: 1). Controls the resolution of the screenshot.

**size\_preset** `string`

Predefined screen size preset to use instead of specifying width and height manually. Supported values include:

<ul>
  <li>`QVGA` - 320×240</li>
  <li>`VGA` - 640×480</li>
  <li>`SVGA` - 800×600</li>
  <li>`HD` - 1280×720</li>
  <li>`HD+` - 1600×900</li>
  <li>`SXGA` - 1280×1024</li>
  <li>`FHD` - 1920×1080</li>
  <li>`2K` - 2048×1080</li>
  <li>`2K QHD` - 2560×1440</li>
  <li>`5K` - 5120×2880</li>
  <li>`4K UHD` - 3840×2160</li>
</ul>

See the full list of screen size presets [here](https://jigsaw-13.mintlify.site/docs/additional-resources/size-preset.md)

**is\_mobile** `boolean` (default: false)

When set to true, emulates a mobile device viewport and takes the meta viewport tag into account.

**dark\_mode** `boolean` (default: false)

When set to true, forces the page to render in dark mode using the CSS prefers-color-scheme media feature.

**use\_graphic\_renderer** `boolean` (default: false)

Enables WebGL, GPU acceleration, and other 3D APIs. Note: This option may impact performance and increase API latency.

**goto\_options** `object`

Custom page-load behavior settings.

**Properties**

**timeout** `number` (default: 15000)

Maximum time to wait for the page to load, in milliseconds (max: 15000ms).

**wait\_until** `string`

Event to wait for before considering navigation complete:

<ul>
  <li>`load` - Wait for the window\.load event</li>
  <li>`domcontentloaded` - Wait for the DOMContentLoaded event</li>
  <li>`networkidle0` - Wait until there are no network connections for at least 500ms</li>
  <li>`networkidle2` - Wait until there are no more than 2 network connections for at least 500ms</li>
</ul>

**pdf\_display\_header\_footer** `boolean` (default: false)

When set to true, displays header and footer in PDF output. Only applies when `type` is set to `pdf`.

**pdf\_print\_background** `boolean` (default: false)

When set to true, prints background graphics in PDF output. Only applies when `type` is set to `pdf`.

**pdf\_page\_range** `string`

Page ranges to print in PDF format (e.g., '1-5, 8, 11-13'). Only applies when `type` is set to `pdf`.

**return\_type** `string` (default: binary)

The specified return type for the response

<ul>
  <li>`url`</li>
  <li>`base64`</li>
  <li>`binary`</li>
</ul>

<Snippet file="header.mdx" />

## Response

The response format depends on the `return_type` parameter:

#### URL Response

return\_type: "url" or "base64"

**success** `boolean`

Indicates whether the call was successful.

**\_usage** `object`

Usage information for the API call.

**\_usage**

**input\_tokens** `number`

Number of input tokens processed.

**output\_tokens** `number`

Number of output tokens generated.

**inference\_time\_tokens** `number`

Number of tokens processed during inference time.

**total\_tokens** `number`

Total number of tokens used (input + output).

**log\_id** `string`

A unique identifier for the request

**url** `string`

The URL of the generated file (image or PDF) that can be accessed directly.

#### Binary Response

return\_type: "binary"

The API returns the generated file (image or PDF) directly in the response body as binary data.

## Common Use Cases

### Website Screenshots

Capture screenshots of websites for:

* Monitoring and testing
* Generating previews or thumbnails
* Creating social media images
* Archiving webpage states

### HTML to Image Conversion

Convert HTML snippets to images for:

* Email templates
* Social media posts
* Dynamic image generation
* Creating graphics from templates

### PDF Generation

Create PDFs from webpages for:

* Generating reports
* Creating downloadable content
* Archiving articles or documentation
* Creating printable versions of web content

### Responsive Design Testing

Test how websites appear on different screen sizes:

* Mobile vs. desktop views
* Various device dimensions
* Light vs. dark mode

## Best Practices

1. **Optimal Quality Settings**:

   * For lossless quality, use PNG format with `quality: 100`
   * For smaller file sizes with good quality, use WebP format with `quality: 80-90`
   * For the smallest file sizes (where quality is less critical), use JPEG format with `quality: 70-80`

2. **Page Loading**:

   * Use `wait_until: "networkidle0"` for dynamic websites that load content via JavaScript
   * Set appropriate `timeout` values for websites that take longer to load
   * Consider using explicit `width` and `height` to match the content dimensions

3. **PDF Configuration**:
   * Enable `pdf_print_background` when capturing colorful websites as PDFs
   * Use `pdf_page_range` to capture only specific pages for large websites
   * Set appropriate page dimensions with `width` and `height` for better PDF layout

```javascript Javascript theme={null}
import { JigsawStack } from "jigsawstack";

const jigsaw = JigsawStack({ apiKey: "your-api-key" });

const response = await jigsaw.web.html_to_any({
  "url": "https://news.ycombinator.com/",
  "return_type": "url"
})
```

```python Python theme={null}
from jigsawstack import JigsawStack

jigsaw = JigsawStack(api_key="your-api-key")

response = jigsaw.web.html_to_any({
  "url": "https://news.ycombinator.com/",
  "return_type": "url"
})
```

```bash Curl theme={null}
curl https://api.jigsawstack.com/v1/web/html_to_any \
-X POST \
-H 'Content-Type: application/json' \
-H 'x-api-key: your-api-key' \
-d '{"url":"https://news.ycombinator.com/","return_type":"url"}'
```

```php PHP theme={null}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.jigsawstack.com/v1/web/html_to_any');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'x-api-key: your-api-key',
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"url":"https://news.ycombinator.com/","return_type":"url"}');

$response = curl_exec($ch);

curl_close($ch);

```

```ruby Ruby theme={null}
require 'net/http'
require 'json'

uri = URI('https://api.jigsawstack.com/v1/web/html_to_any')
req = Net::HTTP::Post.new(uri)
req.content_type = 'application/json'
req['x-api-key'] = 'your-api-key'

req.body = {
'url' => 'https://news.ycombinator.com/',
'return_type' => 'url'
}.to_json

req_options = {
use_ssl: uri.scheme == 'https'
}
res = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
http.request(req)
end

```

```go Go theme={null}
package main

import (
"fmt"
"io"
"log"
"net/http"
"strings"
)

func main() {
client := &http.Client{}
var data = strings.NewReader(`{"url":"https://news.ycombinator.com/","return_type":"url"}`)
req, err := http.NewRequest("POST", "https://api.jigsawstack.com/v1/web/html_to_any", data)
if err != nil {
	log.Fatal(err)
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("x-api-key", "your-api-key")
resp, err := client.Do(req)
if err != nil {
	log.Fatal(err)
}
defer resp.Body.Close()
bodyText, err := io.ReadAll(resp.Body)
if err != nil {
	log.Fatal(err)
}
fmt.Printf("%s\n", bodyText)
}

```

```java Java theme={null}
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse;

HttpClient client = HttpClient.newHttpClient();

HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.jigsawstack.com/v1/web/html_to_any"))
.POST(BodyPublishers.ofString("{\"url\":\"https://news.ycombinator.com/\",\"return_type\":\"url\"}"))
.setHeader("Content-Type", "application/json")
.setHeader("x-api-key", "your-api-key")
.build();

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

```

```swift Swift theme={null}
import Foundation

let jsonData = [
"url": "https://news.ycombinator.com/",
"return_type": "url"
] as [String : Any]
let data = try! JSONSerialization.data(withJSONObject: jsonData, options: [])

let url = URL(string: "https://api.jigsawstack.com/v1/web/html_to_any")!
let headers = [
"Content-Type": "application/json",
"x-api-key": "your-api-key"
]

var request = URLRequest(url: url)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = data as Data

let task = URLSession.shared.dataTask(with: request) { (data, response, error) in
if let error = error {
    print(error)
} else if let data = data {
    let str = String(data: data, encoding: .utf8)
    print(str ?? "")
}
}

task.resume()

```

```dart Dart theme={null}
import 'package:http/http.dart' as http;

void main() async {
final headers = {
'Content-Type': 'application/json',
'x-api-key': 'your-api-key',
};

final data = '{"url":"https://news.ycombinator.com/","return_type":"url"}';

final url = Uri.parse('https://api.jigsawstack.com/v1/web/html_to_any');

final res = await http.post(url, headers: headers, body: data);
final status = res.statusCode;
if (status != 200) throw Exception('http.post error: statusCode= $status');

print(res.body);
}

```

```kotlin Kotlin theme={null}
import java.io.IOException
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody.Companion.toRequestBody

val client = OkHttpClient()

val MEDIA_TYPE = "application/json".toMediaType()

val requestBody = "{\"url\":\"https://news.ycombinator.com/\",\"return_type\":\"url\"}"

val request = Request.Builder()
.url("https://api.jigsawstack.com/v1/web/html_to_any")
.post(requestBody.toRequestBody(MEDIA_TYPE))
.header("Content-Type", "application/json")
.header("x-api-key", "your-api-key")
.build()

client.newCall(request).execute().use { response ->
if (!response.isSuccessful) throw IOException("Unexpected code $response")
response.body!!.string()
}

```

```csharp C# theme={null}
using System.Net.Http.Headers;
using System.Net.Http.Json;

HttpClient client = new HttpClient();

HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "https://api.jigsawstack.com/v1/web/html_to_any");
request.Headers.Add("x-api-key", "your-api-key");
request.Content = JsonContent.Create(new
{
url = "https://news.ycombinator.com/",
return_type = "url"
});
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

HttpResponseMessage response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();

Console.WriteLine(responseBody);
```

```json Response theme={null}
{
  "success": true,
  "url": "https://jigsawstack-temp.b1e91a466694ad4af04df5d05ca12d93.r2.cloudflarestorage.com/temp/b24d5704-b8ce-42be-9a1f-ec412e099da3.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=7b9a19349842b7b1a9e4c2e19f05b232%2F20250916%2Fauto%2Fs3%2Faws4_request&X-Amz-Date=20250916T185141Z&X-Amz-Expires=604800&X-Amz-Signature=94011f103ee982e32a3e26c95cec7504b1112ff912dcdc6b7395670d657711f8&X-Amz-SignedHeaders=host&x-amz-checksum-mode=ENABLED&x-id=GetObject",
  "_usage": {
        "input_tokens": 16,
        "output_tokens": 128,
        "inference_time_tokens": 10588,
        "total_tokens": 10732
  }
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.