How to add text and images to PDF in VB.NET with PDF.co Web API

The tutorial below will demonstrate how to add text and images to PDF in VB.NET

This sample source code below will demonstrate you how to add text and images to PDF in VB.NET. PDF.co 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. It can add text and images to PDF in VB.NET.

This rich sample source code in VB.NET for PDF.co Web API includes the number of functions and options you should do calling the API to add text and images to PDF. Just copy and paste the code into your VB.NET application’s code and follow the instruction. Enjoy writing a code with ready-to-use sample codes in VB.NET.

Free trial version of PDF.co Web API is available for download from our website. Get it to try other source code samples for VB.NET.

On-demand (REST Web API) version:
 Web API (on-demand version)

On-premise offline SDK for Windows:
 60 Day Free Trial (on-premise)

Module1.vb
      
Imports System.IO Imports System.Net Imports Newtonsoft.Json.Linq Module Module1 ' The authentication key (API Key). ' Get your own by registering at https://app.pdf.co/documentation/api Const API_KEY As String = "***********************************" ' Direct URL of source PDF file. Const SourceFileUrl As String = "https://bytescout-com.s3.amazonaws.com/files/demo-files/cloud-api/pdf-edit/sample.pdf" ' Comma-separated list of page indices (Or ranges) to process. Leave empty for all pages. Example '0,2-5,7-'. Const Pages As String = "" ' PDF document password. Leave empty for unprotected documents. Const Password As String = "" ' Destination PDF file name Const DestinationFile As String = ".\result.pdf" ' Image params Private Const Type1 As String = "image" Private Const Width1 As Int32 = 119 Private Const Height1 As Int32 = 32 Private Const ImageUrl As String = "https://bytescout-com.s3.amazonaws.com/files/demo-files/cloud-api/pdf-edit/logo.png" 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) ' Find Text coordinates to add image Dim oCoordinates = FindCoordinates(API_KEY, SourceFileUrl, "Your Company Name") Dim X1 As Int32 = 450 Dim Y1 As Int32 = oCoordinates.y ' * Add image * ' Prepare URL for `PDF Edit` API call Dim query As String = Uri.EscapeUriString(String.Format( "https://api.pdf.co/v1/pdf/edit/add?name={0}&password={1}&pages={2}&url={3}&type={4}&x={5}&y={6}&width={7}&height={8}&urlimage={9}", Path.GetFileName(DestinationFile), Password, Pages, SourceFileUrl, Type1, X1, Y1, Width1, Height1, ImageUrl)) Try ' Execute request Dim response As String = webClient.DownloadString(query) ' 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() ' Download PDF file webClient.DownloadFile(resultFileUrl, DestinationFile) Console.WriteLine("Generated PDF file saved as ""{0}"" file.", DestinationFile) Else Console.WriteLine(json("message").ToString()) 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 ''' <summary> ''' Find result coordinates ''' </summary> Function FindCoordinates(ByVal API_KEY As String, ByVal SourceFileUrl As String, ByVal SearchString As String) As ResultCoOrdinates Dim oResult As New ResultCoOrdinates() ' Create standard .NET web client instance Dim webClient As WebClient = New WebClient() ' Set API Key webClient.Headers.Add("x-api-key", API_KEY) ' Prepare URL for PDF text search API call. ' See documentation: https : //app.pdf.co/documentation/api/1.0/pdf/find.html Dim query As String = Uri.EscapeUriString( String.Format("https://api.pdf.co/v1/pdf/find?url={0}&searchString={1}", SourceFileUrl, SearchString)) Try ' Execute request Dim response As String = webClient.DownloadString(query) ' Parse JSON response Dim json As JObject = JObject.Parse(response) If json("error").ToObject(Of Boolean) = False Then Dim item = json("body")(0) oResult.x = item("left") oResult.y = item("top") oResult.width = item("width") oResult.height = item("height") End If Catch ex As WebException Console.WriteLine(ex.ToString()) End Try webClient.Dispose() Return oResult End Function Class ResultCoOrdinates Public x As Integer Public y As Integer Public width As Integer Public height As Integer End Class End Module

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit PDF.co Web API Home Page

Explore PDF.co Web API Documentation

Explore Samples

Sign Up for PDF.co Web API Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

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

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit PDF.co Web API Home Page

Explore PDF.co Web API Documentation

Explore Samples

Sign Up for PDF.co Web API Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

VIDEO

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit PDF.co Web API Home Page

Explore PDF.co Web API Documentation

Explore Samples

Sign Up for PDF.co Web API Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Related Samples: