Web/HTML To PDF REST API for VB.NET Samples

Forget tedious coding or server management: SelectPdf is a simple API that makes it easy to convert HTML, CSS and JavaScript to PDF. Easily generate PDF documents from HTML code with SelectPdf powerful online REST API.

SelectPdf API is the best when it comes to converting web pages to pdf. Just send your url or html string to our API and get back the perfect PDF document. Externalize the load from your servers. Outsource the html to pdf conversion to SelectPdf REST API and get the best results no matter the platform you are using: Java, PHP, .NET, Ruby, Perl or anything else.

The following examples are in VB.NET for SelectPdf Online API. Make sure that you are interested in the online API, because if you are interested in the .NET library, there are other places where you can find VB.NET samples for SelectPdf .NET Library.

Until recently, we did not provide any .NET samples for the online API, because the recommended product if .NET was available, was our SelectPdf Library for .NET. What changed is that more and more users are moving to systems where the full .NET Framework (required by our .NET library) is not available (they use Azure websites or .NET Core or Mono), but they still code in VB.NET or C#. Here, the online Html to Pdf API comes into play.

There are a variety of methods in .NET that you can use to access a REST API. We will show you 3 of them in this article. One important thing to remember is that the PDF is returned to the client in binary form. Trying to read this binary format as text will cause problems and your PDF will not be saved correctly. So, remember, binary mode for PDF reading.

Later Edit: The recommended approach to access SelectPdf Online REST API from VB.NET is to use the dedicated .NET Client Library for SelectPdf API. Alternatively, you can write your own code to access the API. Below are some examples for this approach.

Example #1 – How to use VB.NET to convert a webpage to PDF and save it on the disk using HttpWebRequest / HttpWebResponse

This code converts an url to pdf in VB.NET using SelectPdf REST API through a POST request. It uses HttpWebRequest / HttpWebResponse (and Newtonsoft for JSON serialization). The content is saved into a file on the disk.

Example #2 – How to use VB.NET to convert a webpage to PDF and save it on the disk using WebClient

This code converts an url to pdf in VB.NET using SelectPdf REST API through a POST request. It uses WebClient (and Newtonsoft for JSON serialization). The content is saved into a file on the disk.

Example #3 – How to use VB.NET to convert a webpage to PDF and save it on the disk using RestSharp

This code converts an url to pdf in VB.NET using SelectPdf REST API through a POST request. It uses RestSharp for the HTTP communication with the API. The content is saved into a file on the disk.

The above samples use only the 2 mandatory parameters (key and url or html) for the html to pdf conversion. For the full list of optional parameters, take a look at SelectPdf HTML To PDF API page. Using the API optional parameters, you can control the page size, orientation and margins in the pdf document, the document information and security, the headers and footers and a lot more.

Hopefully these examples will help you to be on your way using the API for URL to PDF conversion in VB.NET.