Rob Rob is a developer at IDRSolutions, currently working on JPedal and the BuildVu Microservice Example, including the Ruby, Python and C# Clients. In his spare time he enjoys riding his motorcycle, playing guitar in his band and studying languages that don't require a semicolon at the end of each line (currently Bulgarian and Go).

Running BuildVu from other languages

2 min read

A question we get asked pretty often is “Can we use your library to convert PDF to HTML5 with [insert programming language]?

The answer?

Yes! You can use BuildVu with (almost) any programming language.

There are 2 ways you can integrate it with your language of choice. The first is using the command line, then the second involves hosting BuildVu on an application server and running it as a web service you can interact with via a REST API.

1. Via command line

You can run BuildVu directly from the command line, which means that as long as you have Java installed and your chosen language can interact with the command line, you’re good to go. For example, C# can use the Process class, Python can use subprocess, Ruby can use Kernel, etc.

For example, using Python:

from subprocess import call
cmd = 'java -jar path/to/buildvu.jar path/to/input.pdf path/to/output/directory'
call(cmd)

We have plenty of useful documentation on the various options available to you when running BuildVu from the command line here, as well as language specific examples here.

This is a nice, quick and easy setup, but it doesn’t work for everyone. For some people, having Java installed, having to make sure your program is run from the same location as the buildvu jar or provide an absolute path to it isn’t an option – which brings us onto the second option.

2. Run BuildVu as a web service

Alternatively, you can now run BuildVu as a web service using our shiny new BuildVu Microservice Example, which you can interact with using almost any programming language through a simple REST API. Like the first option, no Java coding is necessary, but furthermore you don’t even have to have Java installed (except on the machine running BuildVu and the app server, of course).

It doesn’t take long to set up – all you need to do is:

  1. Clone the microservice example repository
  2. Build the .war file
  3. Deploy it to your app server of choice

That’s all – once you’ve done that you’re ready to go!

(We’ve written some tutorials that give you a step-by-step walkthrough of deployment depending on which app server you’re using.)

On the client side of things, we’ve also put together some handy ‘plug and play’ libraries for the most popular programming languages, including Node.JS, JavaScript, PHP, C#, Ruby and more. Using these, you can get up and running in as little as a few lines of code. See our documentation here.

For example, if I’m using Ruby on Rails:

Install the gem using gem install buildvu (or by adding it to my gemfile and using bundler)…

Add the following 3 lines of code…

require 'buildvu'
buildvu = BuildVu.new('localhost:8080/microservice-example')
buildvu.convert('/path/to/input/file', '/path/to/output/dir')

…and we’re done – my Rails app can now convert PDF to HTML5.

Furthermore, the libraries for each language and the BuildVu Microservice Example are all free and open source (excluding BuildVu itself – though the free trial works just fine too), so if you want to you can make changes, improvements, or simply play around with it. We’re open to pull requests!

Bonus: 3. Using a tool as a ‘bridge’ between languages

As mentioned in an article I wrote a while back – How to run Java applications from other programming languages – there are some great tools out there such as Py4J, IKVM & JRuby that allow 2 different languages to interact with each other using various different means. For example, Py4J communicates with the JVM using a local network socket, while JRuby runs ontop of the JVM itself. If you don’t mind doing some coding or fancy a little challenge, this is something fun to explore!

Have you had any experience using multiple languages alongside each other like this before? We’d also love to hear your feedback – if we’ve missed your favourite app server or language, let us know in the comments below.

If you’re a first-time reader, or simply want to be notified when we post new articles and updates, you can keep up to date by social media (Twitter, Facebook and Google+) or the Blog RSS.

Rob Rob is a developer at IDRSolutions, currently working on JPedal and the BuildVu Microservice Example, including the Ruby, Python and C# Clients. In his spare time he enjoys riding his motorcycle, playing guitar in his band and studying languages that don't require a semicolon at the end of each line (currently Bulgarian and Go).

Leave a Reply

Your email address will not be published. Required fields are marked *