API

SDKs

cloudlayer.io provides an official .NET SDK and community SDKs for several other languages. Since all document generation is driven by a REST API, you can also integrate directly from any language that supports HTTP requests.

Official SDK: .NET C#

The official cloudlayerio-dotnet SDK is a .NET 6 library available on NuGet.

Installation

Visual Studio

Using the Package Manager Console:

Install-Package cloudlayerio-dotnet

Or search for cloudlayerio-dotnet in the NuGet Package Manager.

JetBrains Rider

See JetBrains NuGet documentation.

.NET CLI

dotnet add package cloudlayerio-dotnet

Setup

Get your API key by creating a free account at cloudlayer.io. Your account comes with free API credits for testing.

Initialize the manager with your API key:

var manager = new CloudlayerioManager("<YOUR-API-KEY>");

URL to PDF

var rsp = await manager.UrlToPdf(new UrlToPdf
{
    Url = "https://example.com"
});

// Save the JSON response to the filesystem
await rsp.SaveToFileSystem("C:\\output\\example.json");

// Access the asset URL (only available with async: false)
var url = rsp.Response.AssetUrl;

URL to Image

var rsp = await manager.UrlToImage(new UrlToImage
{
    Url = "https://example.com",
    AutoScroll = true,
    ViewPort = new ViewPort
    {
        Width = 1440,
        Height = 900,
        DeviceScaleFactor = 2
    }
});

var url = rsp.Response.AssetUrl;

HTML to PDF

// HTML must be base64-encoded
var html = Convert.ToBase64String(
    Encoding.UTF8.GetBytes("<html><body><h1>Hello!</h1></body></html>")
);

var rsp = await manager.HtmlToPdf(new HtmlToPdf
{
    Html = html
});

await rsp.SaveToFileSystem("C:\\output\\hello.json");

Template to PDF

var rsp = await manager.TemplateToPdf(new TemplateToPdf
{
    TemplateId = "professional-invoice",
    Data = new Dictionary<string, object>
    {
        ["company_name"] = "Acme Inc.",
        ["invoice_no"] = "INV-001",
        ["locale"] = "en-US",
        ["currency"] = "USD",
        ["items"] = new[]
        {
            new Dictionary<string, object>
            {
                ["title"] = "Web Design",
                ["quantity"] = 10,
                ["unit_price"] = 150.00,
                ["amount"] = null
            }
        }
    }
});

await rsp.SaveToFileSystem("C:\\output\\invoice.json");

Synchronous vs Asynchronous

By default, requests are processed asynchronously. The response is delivered to your configured webhook. To get the result immediately in the response, set Async = false:

var rsp = await manager.UrlToPdf(new UrlToPdf
{
    Url = "https://example.com",
    Async = false
});

// AssetUrl is populated in the synchronous response
var url = rsp.Response.AssetUrl;

Note: For long-running requests (large documents, batch processing), use the default async mode with webhooks to avoid connection timeouts.

Advanced Options

The SDK provides typed classes for all API options, with full IntelliSense support.

Custom Margins

var rsp = await manager.UrlToPdf(new UrlToPdf
{
    Url = "https://example.com",
    Margin = new Margin
    {
        Top = new LayoutDimension(UnitTypes.Pixels, 100),
        Bottom = new LayoutDimension(UnitTypes.Pixels, 100),
        Left = new LayoutDimension(UnitTypes.Pixels, 50),
        Right = new LayoutDimension(UnitTypes.Pixels, 50)
    }
});
var rsp = await manager.UrlToPdf(new UrlToPdf
{
    Url = "https://example.com",
    Margin = new Margin
    {
        Top = new LayoutDimension(UnitTypes.Pixels, 120),
        Bottom = new LayoutDimension(UnitTypes.Pixels, 80)
    },
    HeaderTemplate = new HeaderFooterTemplate
    {
        Method = "extract",
        Selector = ".page-header",
        Style = new Dictionary<string, string>
        {
            ["width"] = "100%",
            ["text-align"] = "center"
        }
    },
    FooterTemplate = new HeaderFooterTemplate
    {
        Selector = ".page-footer",
        Style = new Dictionary<string, string>
        {
            ["width"] = "100%",
            ["font-size"] = "10px",
            ["text-align"] = "center"
        }
    }
});

Viewport Configuration

var rsp = await manager.UrlToImage(new UrlToImage
{
    Url = "https://example.com",
    ViewPort = new ViewPort
    {
        Width = 1920,
        Height = 1080,
        DeviceScaleFactor = 2,
        IsMobile = false,
        IsLandscape = true
    }
});

Response Format

As of v2, the API returns a JSON response rather than binary content. The SaveToFileSystem helper saves this JSON response to disk. The response object is fully typed with properties including:

PropertyTypeDescription
AssetUrlstringURL to the generated asset (populated for sync calls)
StatusstringJob status (success, error, etc.)
JobIdstringUnique identifier for the generation job

For the full set of response properties and request options, see the source code.

Community SDKs

The following community SDKs are available:

LanguageRepositoryPackage Manager
.NET F#github.com/cloudlayerio/cloudlayerio-fsharpNuGet
PHPgithub.com/cloudlayerio/cloudlayerio-phpComposer
Pythongithub.com/cloudlayerio/cloudlayerio-pythonpip
Rubygithub.com/cloudlayerio/cloudlayerio-rubygem
Gogithub.com/cloudlayerio/cloudlayerio-gogo get
Javagithub.com/cloudlayerio/cloudlayerio-javaMaven

Using the REST API Directly

The cloudlayer.io REST API can be called from any language. All you need is:

  1. Your API key (passed via the x-api-key header)
  2. The ability to make HTTP POST requests with JSON bodies
  3. Base URL: https://api.cloudlayer.io/v2

Quick Reference: API Endpoints

EndpointDescription
POST /url/pdfConvert a URL to PDF
POST /url/imageConvert a URL to an image
POST /html/pdfConvert HTML to PDF
POST /html/imageConvert HTML to an image
POST /template/pdfGenerate a PDF from a template
POST /template/imageGenerate an image from a template
GET /url/pdfSimple URL to PDF (query params only)

cURL Example

curl --request POST \
  --url https://api.cloudlayer.io/v2/url/pdf \
  --header 'Content-Type: application/json' \
  --header 'x-api-key: <YOUR-API-KEY>' \
  --data '{
    "url": "https://example.com",
    "async": false
  }'

JavaScript (Node.js / Bun / Deno)

const response = await fetch("https://api.cloudlayer.io/v2/url/pdf", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "x-api-key": "<YOUR-API-KEY>",
  },
  body: JSON.stringify({
    url: "https://example.com",
    async: false,
  }),
});

const result = await response.json();
console.log(result.assetUrl);

Python

import requests

response = requests.post(
    "https://api.cloudlayer.io/v2/url/pdf",
    headers={
        "Content-Type": "application/json",
        "x-api-key": "<YOUR-API-KEY>",
    },
    json={
        "url": "https://example.com",
        "async": False,
    },
)

result = response.json()
print(result["assetUrl"])

Tip: Even if your language does not have a dedicated SDK, the REST API is straightforward to use. See the Authentication Examples, HTML Examples, and URL Examples for more language-specific code samples.