Introduction
This tutorial explains how to convert PDF files to SVG in C# using the hosted BuildVu Cloud API, including examples such as:
- The IDRsolutions trial version or cloud subscription
- A self-hosted BuildVu microservice instance
Although the above services can be accessed via standard HTTP requests, this tutorial uses our open-source C# IDRCloudClient, which offers an easy-to-use C# wrapper for the REST API.
SVGs for Display in C#
SVG is often better than PDF for C# developers when displaying graphics because SVGs are resolution-independent, always crisp at any size or on any device, and usually much smaller and easier to edit or style programmatically.
SVG can be inserted directly into C# applications, scaled, positioned, and updated in real time, making UI design and visual elements more flexible and responsive.
In contrast, PDFs are better for static document layouts or archiving, but less suited for interactive or dynamic graphic display. SVGs are also less susceptible to attacks because they do not run any code. SVGs can also reduce exploitation potential since they do not include code.
Prerequisites
Install the idrsolutions-csharp-client package via NuGet using the following command:
nuget install idrsolutions-csharp-client
Code Example
Below is a simple code example demonstrating how to convert PDF files to SVG. Additional configuration options and advanced features are described further down.
using System;
using System.Collections.Generic;
using idrsolutions_csharp_client;
class ExampleUsage
{
static void Main(string[] args)
{
var client = new IDRCloudClient("https://cloud.idrsolutions.com/cloud/" + IDRCloudClient.BUILDVU);
try
{
Dictionary parameters = new Dictionary
{
//["token"] = "Token", //Required only when connecting to the IDRsolutions trial and cloud subscription service
["input"] = IDRCloudClient.UPLOAD,
["file"] = "path/to/input.pdf"
};
Dictionary 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("Conversion failed: " + e.Message);
}
}
}
Return result to a callback URL
The BuildVu Microservice can accept a callback URL to report the status of a conversion once it is complete. Using a callback URL eliminates the need to poll the service to check when the conversion has finished. You can provide the callback URL to the convert method as shown below.
Dictionary parameters = new Dictionary
{
//["token"] = "Token", //Required only when connecting to the IDRsolutions trial and cloud subscription service
["callbackUrl"] = "http://listener.url",
["input"] = IDRCloudClient.UPLOAD,
["file"] = "path/to/input.pdf"
};
Configuration Options
The BuildVu API accepts a stringified JSON object with key-value pair configuration options to customize your conversion. These settings should be included in the parameters array. A complete list of configuration options for converting PDF files to SVG is available here.
["settings"] = "{\"key\":\"value\",\"key\":\"value\"}"
Upload by URL
In addition to uploading a local file, you can provide a URL for the BuildVu Microservice to download and convert. To do this, replace the input and file values in the parameters variable with the following.
["input"] = IDRCloudClient.DOWNLOAD
["url"] = "http://exampleURL/exampleFile.pdf"
Using Authentication
If your self-hosted BuildVu Microservice requires a username and password to convert PDF files to SVG, you must include them with each conversion request. These credentials are passed as username and password variables to the convert method, as shown below.
var client = new IDRCloudClient("http://exampleURL.com/" + IDRCloudClient.BUILDVU, "username", "password");
BuildVu allows you to
| View PDF files in a Web app |
| Convert PDF documents to HTML5 |
| Parse PDF documents as HTML |
What is BuildVu?
BuildVu is a commercial SDK for converting PDF files into standalone HTML or SVG.
Why use BuildVu?
BuildVu allows you to integrate PDF into your HTML workflow effortlessly and securely by producing clean HTML that is easy for developers to work with.
What licenses are available?
We have 3 licenses available:
Cloud for conversion using the shared IDRsolutions cloud server, Self hosted server option for your own cloud or on-premise servers, and Enterprise for more demanding requirements.
How to use BuildVu?
Want to learn more about BuildVu and how to use it, we have plenty of tutorials and guides to help you.