Access the BuildVu Microservice using C#
Table of contents
- Introduction
- Prerequisites
- Code Example
- Configuration Options
- Upload by URL
- Using Authentication
- Further details
Introduction
The following tutorial shows you how to convert PDF files to HTML or SVG using a hosted BuildVu cloud API, such as:
- the IDRsolutions trial server
- the IDRsolutions cloud subscription server
- your own self-hosted BuildVu microservice
Whilst all the above services can be accessed with plain old HTTP requests, this tutorial uses our open source C# IDRCloudClient which provides a simple C# wrapper around the REST API.
Prerequisites
Using nuget, install the idrsolutions-csharp-client package with the following command:
nuget install idrsolutions-csharp-client
Code Example
Here is a basic code example to convert PDF files to HTML or SVG. Configuration options and advanced features can be found below.
using System;
using System.Collections.Generic;
using idrsolutions-csharp-client;
class ExampleUsage
{
static void Main(string[] args)
{
var client = new IDRCloudClient("http://exampleURL.com/" + IDRCloudClient.BUILDVU);
try
{
Dictionary<string, string> parameters = new Dictionary<string, string>
{
//["token"] = "Token", //Required only when connecting to the IDRsolutions trial or cloud subscription servers
["input"] = IDRCloudClient.UPLOAD,
["file"] = "path/to/input.pdf"
};
Dictionary<string, string> results = client.Convert(parameters);
String outputUrl = results.GetValueOrDefault("downloadUrl", "No download URL provided");
client.DownloadResult(results, "path/to/output/dir");
Console.WriteLine("Converted: " + outputUrl);
}
catch (Exception e)
{
Console.WriteLine("Download URL: " + e.Message);
}
}
}
Configuration Options
The BuildVu API accepts a stringified JSON object containing key value pair configuration options to customise your conversion. The settings should be added to the parameters array. A full list of the configuration options to convert PDF files to HTML or SVG can be found here.
["settings"] = "{\"key\":\"value\",\"key\":\"value\"}"
Upload by URL
As well as uploading a local file you can also provide a URL which the BuildVu Microservice will download and then perform the conversion. To do this you should replace the input and file values in the parameters variable with the following.
["input"] = IDRCloudClient.DOWNLOAD
["url"] = "http://exampleURL/exampleFile.pdf"
Using Authentication
If the BuildVu Microservice requires authentication, you will need to provide a username and password. These are provided by passing two variables named username and password to the convert method as shown below.
var client = new IDRCloudClient("http://exampleURL.com/" + IDRCloudClient.BUILDVU, "username", "password");
Further details
IDRCloudClient on GitHub
IDRCloudClient on Nuget
BuildVu Microservice API
BuildVu Microservice Use