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

This code in VB.NET shows how to add text and images to PDF with this how to tutorial

We made thousands of pre-made source code pieces for easy implementation in your own programming projects. PDF.co Web API: the Rest API that provides set of data extraction functions, tools for documents manipulation, splitting and merging of pdf files. Includes built-in OCR, images recognition, can generate and read barcodes from images, scans and pdf. It can add text and images to PDF in VB.NET.

Fast application programming interfaces of PDF.co Web API for VB.NET plus the instruction and the code below will help you quickly learn how to add text and images to PDF. In order to implement the functionality, you should copy and paste this code for VB.NET below into your code editor with your app, compile and run your application. Detailed tutorials and documentation are available along with installed PDF.co Web API if you’d like to dive deeper into the topic and the details of the API.

You can download free trial version of PDF.co Web API from our website to see and try many others 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" ' Text params Private Const Type As String = "annotation" Private Const Text As String = "Some notes will go here... Some notes will go here.... Some notes will go here....." Private Const FontName As String = "Times New Roman" Private Const FontSize As Decimal = 12 Private Const Color As String = "FF0000" 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 Annotation Dim oCoordinates = FindCoordinates(API_KEY, SourceFileUrl, "Notes") Dim X As Integer = oCoordinates.x Dim Y As Integer = oCoordinates.y + 25 ' * Add text annotations * ' 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}&text={7}&fontname={8}&size={9}&color={10}", Path.GetFileName(DestinationFile), Password, Pages, SourceFileUrl, Type, X, Y, Text, FontName, FontSize, Color)) 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: