ByteScout Cloud API Server - PDF To Excel API - VB.NET - Convert PDF To XLS From Uploaded File (WinForms) - ByteScout

ByteScout Cloud API Server – PDF To Excel API – VB.NET – Convert PDF To XLS From Uploaded File (WinForms)

  • Home
  • /
  • Articles
  • /
  • ByteScout Cloud API Server – PDF To Excel API – VB.NET – Convert PDF To XLS From Uploaded File (WinForms)

How to convert PDF to XLS from uploaded file (winforms) for PDF to excel API in VB.NET and ByteScout Cloud API Server

Step By Step Instructions on how to convert PDF to XLS from uploaded file (winforms) for PDF to excel API in VB.NET

The sample source codes on this page will show you how to create PDF to excel API in VB.NET. ByteScout Cloud API Server helps with PDF to excel API in VB.NET. ByteScout Cloud API Server is the ready to use Web API Server that can be deployed in less than 30 minutes into your own in-house server or into private cloud server. Can store data on in-house local server based storage or in Amazon AWS S3 bucket. Processing data solely on the server using buil-in ByteScout powered engine, no cloud services are used to process your data!.

Use the code displayed below in your application to save a lot of time on writing and testing code. For implementation of this functionality, please copy and paste the code below into your app using code editor. Then compile and run your app. Want to see how it works with your data then code testing will allow the function to be tested and work properly.

Our website provides free trial version of ByteScout Cloud API Server that gives source code samples to assist with your VB.NET project.

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

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

Form1.Designer.vb
      
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _ Partial Class Form1 Inherits System.Windows.Forms.Form 'Form overrides dispose to clean up the component list. <System.Diagnostics.DebuggerNonUserCode()> _ Protected Overrides Sub Dispose(ByVal disposing As Boolean) Try If disposing AndAlso components IsNot Nothing Then components.Dispose() End If Finally MyBase.Dispose(disposing) End Try End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. <System.Diagnostics.DebuggerStepThrough()> _ Private Sub InitializeComponent() Me.cmbConvertTo = New System.Windows.Forms.ComboBox() Me.label4 = New System.Windows.Forms.Label() Me.btnConvert = New System.Windows.Forms.Button() Me.cmbOutputAs = New System.Windows.Forms.ComboBox() Me.label3 = New System.Windows.Forms.Label() Me.btnSelectInputFile = New System.Windows.Forms.Button() Me.txtInputPDFFileName = New System.Windows.Forms.TextBox() Me.label2 = New System.Windows.Forms.Label() Me.label1 = New System.Windows.Forms.Label() Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog() Me.SuspendLayout() ' 'cmbConvertTo ' Me.cmbConvertTo.FormattingEnabled = True Me.cmbConvertTo.Items.AddRange(New Object() {"XLS", "XLSX"}) Me.cmbConvertTo.Location = New System.Drawing.Point(116, 101) Me.cmbConvertTo.Name = "cmbConvertTo" Me.cmbConvertTo.Size = New System.Drawing.Size(430, 24) Me.cmbConvertTo.TabIndex = 19 ' 'label4 ' Me.label4.AutoSize = True Me.label4.Location = New System.Drawing.Point(22, 101) Me.label4.Name = "label4" Me.label4.Size = New System.Drawing.Size(78, 17) Me.label4.TabIndex = 18 Me.label4.Text = "Convert To" ' 'btnConvert ' Me.btnConvert.Location = New System.Drawing.Point(25, 184) Me.btnConvert.Name = "btnConvert" Me.btnConvert.Size = New System.Drawing.Size(194, 43) Me.btnConvert.TabIndex = 17 Me.btnConvert.Text = "Convert" Me.btnConvert.UseVisualStyleBackColor = True ' 'cmbOutputAs ' Me.cmbOutputAs.FormattingEnabled = True Me.cmbOutputAs.Items.AddRange(New Object() {"URL to output file", "inline content"}) Me.cmbOutputAs.Location = New System.Drawing.Point(116, 141) Me.cmbOutputAs.Name = "cmbOutputAs" Me.cmbOutputAs.Size = New System.Drawing.Size(430, 24) Me.cmbOutputAs.TabIndex = 16 ' 'label3 ' Me.label3.AutoSize = True Me.label3.Location = New System.Drawing.Point(22, 141) Me.label3.Name = "label3" Me.label3.Size = New System.Drawing.Size(71, 17) Me.label3.TabIndex = 15 Me.label3.Text = "Output As" ' 'btnSelectInputFile ' Me.btnSelectInputFile.Font = New System.Drawing.Font("Microsoft Sans Serif", 7.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.btnSelectInputFile.Location = New System.Drawing.Point(420, 54) Me.btnSelectInputFile.Name = "btnSelectInputFile" Me.btnSelectInputFile.Size = New System.Drawing.Size(126, 36) Me.btnSelectInputFile.TabIndex = 14 Me.btnSelectInputFile.Text = "Select input File" Me.btnSelectInputFile.UseVisualStyleBackColor = True ' 'txtInputPDFFileName ' Me.txtInputPDFFileName.Location = New System.Drawing.Point(124, 56) Me.txtInputPDFFileName.Name = "txtInputPDFFileName" Me.txtInputPDFFileName.Size = New System.Drawing.Size(290, 22) Me.txtInputPDFFileName.TabIndex = 13 ' 'label2 ' Me.label2.AutoSize = True Me.label2.Location = New System.Drawing.Point(22, 59) Me.label2.Name = "label2" Me.label2.Size = New System.Drawing.Size(96, 17) Me.label2.TabIndex = 12 Me.label2.Text = "Input PDF File" ' 'OpenFileDialog1 ' Me.OpenFileDialog1.FileName = "OpenFileDialog1" ' 'Form1 ' Me.AutoScaleDimensions = New System.Drawing.SizeF(8.0!, 16.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.ClientSize = New System.Drawing.Size(594, 251) Me.Controls.Add(Me.cmbConvertTo) Me.Controls.Add(Me.label4) Me.Controls.Add(Me.btnConvert) Me.Controls.Add(Me.cmbOutputAs) Me.Controls.Add(Me.label3) Me.Controls.Add(Me.btnSelectInputFile) Me.Controls.Add(Me.txtInputPDFFileName) Me.Controls.Add(Me.label2) Me.Name = "Form1" Me.Text = "Cloud API: PDF to Excel Conversion" Me.ResumeLayout(False) Me.PerformLayout() End Sub Private WithEvents cmbConvertTo As ComboBox Private WithEvents label4 As Label Private WithEvents btnConvert As Button Private WithEvents cmbOutputAs As ComboBox Private WithEvents label3 As Label Private WithEvents btnSelectInputFile As Button Private WithEvents txtInputPDFFileName As TextBox Private WithEvents label2 As Label Private WithEvents label1 As Label Friend WithEvents OpenFileDialog1 As OpenFileDialog End Class

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout Cloud API Server Home Page

Explore ByteScout Cloud API Server Documentation

Explore Samples

Sign Up for ByteScout Cloud API Server Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Form1.vb
      
Imports System.IO Imports System.Net Imports Newtonsoft.Json.Linq ' Please NOTE: In this sample we're assuming Cloud Api Server is hosted at "https://localhost". ' If it's not then please replace this with with your hosting url. Public Class Form1 #Region "File Selection" Private Sub btnSelectInputFile_Click(sender As Object, e As EventArgs) Handles btnSelectInputFile.Click OpenFileDialog1.ShowDialog() End Sub Private Sub OpenFileDialog1_FileOk(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk txtInputPDFFileName.Text = OpenFileDialog1.FileName End Sub #End Region #Region "Convert PDF to Excel" ''' <summary> ''' Perform convert PDF to Excel ''' </summary> Private Sub btnConvert_Click(sender As Object, e As EventArgs) Handles btnConvert.Click Try If (ValidateInputs()) Then ' 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 = "" ' Checks whether convert to as inline content. Dim isInline As Boolean = Convert.ToString(cmbOutputAs.SelectedItem).ToLower() = "inline content" ' Destination file name Dim DestinationFile As String = String.Format(".\{0}.{1}", Path.GetFileNameWithoutExtension(txtInputPDFFileName.Text), Convert.ToString(cmbConvertTo.SelectedItem).ToLower()) ' Create standard .NET web client instance Dim webClient As WebClient = New WebClient() ' 1. RETRIEVE THE PRESIGNED URL TO UPLOAD THE FILE. ' * If you already have a direct file URL, skip to the step 3. ' Prepare URL for `Get Presigned URL` API call Dim query As String = Uri.EscapeUriString( String.Format("https://localhost/file/upload/get-presigned-url?contenttype=application/octet-stream&name={0}", Path.GetFileName(txtInputPDFFileName.Text))) ' 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 to use for the file upload Dim uploadUrl As String = json("presignedUrl").ToString() Dim uploadedFileUrl As String = json("url").ToString() ' 2. UPLOAD THE FILE TO CLOUD. webClient.Headers.Add("content-type", "application/octet-stream") webClient.UploadFile(uploadUrl, "PUT", txtInputPDFFileName.Text) webClient.Headers.Remove("content-type") ' 3. CONVERT UPLOADED PDF FILE TO Excel ' Prepare URL for `PDF To Excel` API call query = Uri.EscapeUriString( String.Format("https://localhost/pdf/convert/to/{4}?name={0}&password={1}&pages={2}&url={3}&encrypt=true&inline={5}", Path.GetFileName(DestinationFile), Password, Pages, uploadedFileUrl, Convert.ToString(cmbConvertTo.SelectedItem).ToLower(), isInline)) ' Execute request response = webClient.DownloadString(query) ' Parse JSON response json = JObject.Parse(response) If json("error").ToObject(Of Boolean)() = False Then ' Get URL of generated Excel file Dim resultFileUrl As String = json("url").ToString() ' Download Excel output file webClient.DownloadFile(resultFileUrl, DestinationFile) MessageBox.Show({code}quot;Generated XLS file saved as {DestinationFile} file.", "Success!") ' Open Downloaded output file Process.Start(DestinationFile) Else MessageBox.Show(json("message").ToString()) End If Else MessageBox.Show(json("message").ToString()) End If webClient.Dispose() End If Catch ex As Exception MessageBox.Show(ex.Message, "Error") End Try End Sub ''' <summary> ''' Validates form inputs ''' </summary> ''' <returns></returns> Private Function ValidateInputs() As Boolean If (String.IsNullOrEmpty(txtInputPDFFileName.Text)) Then Throw New Exception("Input PDf file must be selected/entered.") End If If (Not System.IO.File.Exists(txtInputPDFFileName.Text)) Then Throw New Exception("Input file does not exits.") End If If (System.IO.Path.GetExtension(txtInputPDFFileName.Text).ToLower() <> ".pdf") Then Throw New Exception("Input file must be PDF") End If If (String.IsNullOrEmpty(Convert.ToString(cmbConvertTo.SelectedItem))) Then Throw New Exception("Please select convert to option.") End If If (String.IsNullOrEmpty(Convert.ToString(cmbOutputAs.SelectedItem))) Then Throw New Exception("Please select output-as option") End If Return True End Function #End Region End Class

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout Cloud API Server Home Page

Explore ByteScout Cloud API Server Documentation

Explore Samples

Sign Up for ByteScout Cloud API Server 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="11.0.2" targetFramework="net40" /> </packages>

ON-PREMISE OFFLINE SDK

60 Day Free Trial or Visit ByteScout Cloud API Server Home Page

Explore ByteScout Cloud API Server Documentation

Explore Samples

Sign Up for ByteScout Cloud API Server 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 ByteScout Cloud API Server Home Page

Explore ByteScout Cloud API Server Documentation

Explore Samples

Sign Up for ByteScout Cloud API Server Online Training

ON-DEMAND REST WEB API

Get Your API Key

Explore Web API Docs

Explore Web API Samples

Tutorials:

prev
next