Sign up free
Documentation
Type to search. Use the down arrow to browse results, or Escape to close them.

Java, C#, PHP & Ruby

Build with the official v0.4.1 Java, .NET, PHP and Ruby SDKs for image vectorization and saved vector downloads.

These four Forge-generated SDKs have zero external runtime dependencies. Set VECTALI_API_KEY in your server environment before running a snippet.

Java

Java 11+ uses the standard library. Add com.vectali:vectali-java 0.4.1 from Maven Central to your pom.xml (or implementation("com.vectali:vectali-java:0.4.1") in Gradle).

<!-- Maven Central (pom.xml) -->
<dependency>
  <groupId>com.vectali</groupId>
  <artifactId>vectali-java</artifactId>
  <version>0.4.1</version>
</dependency>
import com.vectali.client.VectaliClient;
import java.nio.file.Files;
import java.nio.file.Path;

class Example {
    public static void main(String[] args) throws Exception {
        var client = new VectaliClient(System.getenv("VECTALI_API_KEY"));
        var result = client.convert(Path.of("logo.png"));
        Files.writeString(Path.of("logo.svg"), result.svg());
        Files.write(Path.of("logo.pdf"), client.download(result.conversionId(), "pdf"));
    }
}

convert accepts Path, byte[] or InputStream. Close supplied streams yourself and reopen them on retry. For a path, pass the saved key as the second argument. For bytes or a stream, pass the filename and key as the second and third arguments. Catch com.vectali.client.ApiException and read statusCode() and headers(). I/O failures use IOException.

C# / .NET

With .NET 8+, build the Vectali.Client v0.4.1 source and add it to your project from the local package directory.

git clone --branch v0.4.1 --depth 1 https://github.com/vectali/vectali-dotnet.git
dotnet pack vectali-dotnet/src/Vectali.Client -o ./local-packages
dotnet add package Vectali.Client --version 0.4.1 --source ./local-packages
using System;
using System.IO;
using Vectali.Client;

using var client = new VectaliClient(Environment.GetEnvironmentVariable("VECTALI_API_KEY")!);
var result = await client.ConvertAsync("logo.png");
await File.WriteAllTextAsync("logo.svg", result.Svg);
await File.WriteAllBytesAsync("logo.pdf", await client.DownloadAsync(result.ConversionId, "pdf"));

ConvertAsync accepts a path, byte[] or Stream. Byte and stream overloads accept filename and contentType. Pass the stored key as idempotencyKey and reopen or rewind borrowed streams before retrying. Catch VectaliException and use StatusCode, Headers and Body for API failures.

PHP

PHP 8.2+ uses the curl and json extensions. Install vectali/vectali (v0.4.1) from Packagist with Composer.

composer require vectali/vectali
<?php
require 'vendor/autoload.php';

$client = new Vectali\Client(getenv('VECTALI_API_KEY'));
$result = $client->convert('logo.png');
file_put_contents('logo.svg', $result->svg);
file_put_contents('logo.pdf', $client->download($result->conversionId, 'pdf'));

convert accepts a path, binary string, SplFileObject or stream resource. Pass a filename for binary strings and streams, close borrowed streams yourself and reuse the saved idempotencyKey on retry. Catch Vectali\ApiException and inspect $error->statusCode, $error->headers and $error->body.

Ruby

Ruby 3.1+ uses no external runtime gems. Install vectali 0.4.1 from RubyGems (source: vectali/vectali-ruby).

gem install vectali
require 'pathname'
require 'vectali'

client = Vectali::Client.new(ENV.fetch('VECTALI_API_KEY'))
result = client.convert(Pathname('logo.png'))
File.write('logo.svg', result.svg)
File.binwrite('logo.pdf', client.download(result.conversion_id, 'pdf'))

convert accepts a Pathname, path string, binary String or IO. Supply a filename for raw binary data and close any IO you pass. Set idempotency_key: to the job’s saved ID. Rescue Vectali::ApiError and check error.status_code and error.headers. Vectali::RateLimitError is a subclass for HTTP 429 responses.

Retrying conversions

The SDKs generate a new idempotency key when you omit it. Store one key per conversion job and reuse it with the original bytes. For 429, read Retry-After before rescheduling. See errors and recovery and the idempotency contract.