How to generate PDF invoice from HTML template for HTML to PDF API in VB.NET and Web API

How to generate PDF invoice from HTML template for HTML to PDF API in VB.NET: Step By Step Tutorial

Writing of the code to generate PDF invoice from HTML template in VB.NET can be done by developers of any level using Web API. Web API was made to help with HTML to PDF API in VB.NET. Web API is the flexible Web API that includes full set of functions from e-signature requests to data extraction, OCR, images recognition, pdf splitting and pdf splitting. Can also generate barcodes and read barcodes from images, scans and pdf.

Fast application programming interfaces of Web API for VB.NET plus the instruction and the code below will help to learn how to generate PDF invoice from HTML template. Sample code in VB.NET is all you need. Copy-paste it to your the code editor, then add a reference to Web API and you are ready to try it! Enjoy writing a code with ready-to-use sample VB.NET codes to add HTML to PDF API functions using Web API in VB.NET.

Trial version of ByteScout is available for free download from our website. This and other source code samples for VB.NET and other programming languages are available.

Try Web API today:  60 Day Free Trial (on-premise) or  Web API (on-demand version)

Imports System.IO Imports System.Net Imports Newtonsoft.Json.Linq Module Module1 ' The authentication key (API Key). ' Get your own by registering at Const API_KEY As String = "***********************************" ' HTML template Dim template As String = File.ReadAllText(".\invoice_template.html") ' Data to fill the template Dim templateData As String = File.ReadAllText(".\invoice_data.json") ' Destination PDF file name Const DestinationFile As String = ".\result.pdf" Sub Main() ' Create standard .NET web client instance Dim webClient As WebClient = New WebClient() ' Set API Key webClient.Headers.Add("x-api-key", API_KEY) Try ' Prepare URL for HTML to PDF API call Dim request As String = Uri.EscapeUriString(String.Format( "{0}", Path.GetFileName(DestinationFile))) ' Prepare request body in JSON format Dim jsonObject As JObject = New JObject( New JProperty("html", template), New JProperty("templateData", templateData)) webClient.Headers.Add("Content-Type", "application/json") ' Execute request Dim response As String = webClient.UploadString(request, jsonObject.ToString()) ' Parse JSON response Dim json As JObject = JObject.Parse(response) If json("error").ToObject(Of Boolean) = False Then ' Get URL of generated PDF file Dim resultFileUrl As String = json("url").ToString() webClient.Headers.Remove("Content-Type") ' remove the header required for only the previous request ' Download the PDF file webClient.DownloadFile(resultFileUrl, DestinationFile) Console.WriteLine("Generated PDF document saved as ""{0}"" file.", DestinationFile) End If Catch ex As WebException Console.WriteLine(ex.ToString()) End Try webClient.Dispose() Console.WriteLine() Console.WriteLine("Press any key...") Console.ReadKey() End Sub End Module

Try Web API today:  60 Day Free Trial (on-premise) or  Web API (on-demand version)

<?xml version="1.0" encoding="utf-8"?> <packages> <package id="Newtonsoft.Json" version="10.0.3" targetFramework="net40" /> </packages>

Try Web API today:  60 Day Free Trial (on-premise) or  Web API (on-demand version)



Get 60 Day Free Trial or Visit Web API Home Page

Explore Web API Documentation

Get Web API Free Training


Get Your Free API Key

Explore Web API Documentation

Related Samples: