VB.NET and PDF
This document contains a sample project which shows how webPDFs "converter" web service (OOoConverter) can be accessed using VB.NET 2008 Express. The code is based on the assumption, that the webPDF server is running on the same machine on which the VB.NET project is being executed.
The code is intended for demo purposes only and has to be adapted to local requirements.
Imports System.IO
Public Class FormMain
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' access to Web service
Dim oTestWebservice As OOoConverterService.OOoConverter = New
OOoConverterService.OOoConverterClient
' return object for Web service
Dim ret As OOoConverterService.convertSimpleResponse = Nothing
' parameter object for Web service
Dim options As OOoConverterService.convertSimpleRequest = New
OOoConverterService.convertSimpleRequest
' set Web service options
' options.options = "pdf.archive=1" ' PDF/A
options.options = "pdf.encryptDocument=true&pdf.
restrictPermissions=true&pdf.permissionPassword=abc"
options.sourceExtension = ".doc"
options.targetExtension = ".pdf"
' Read source file ("bin\debug")
Dim fInfo As New FileInfo(TextBoxFileName.Text)
Dim numBytes As Long = fInfo.Length
Dim fStream As New FileStream(TextBoxFileName.Text, FileMode.Open,
FileAccess.Read)
Dim br As New BinaryReader(fStream)
Dim data As Byte() = br.ReadBytes(CInt(numBytes))
' assign file content to Web service object
options.fileContent = data
' show the number of bytes in the array
TextBoxFileSize.Text = Convert.ToString(data.Length)
br.Close()
fStream.Close()
Try
' call the Web service
ret = oTestWebservice.convertSimple(options)
Catch ex As Exception
' catch the exception
MessageBox.Show(ex.Message.ToString(), "Info")
Return
End Try
' save the returned file to disk
Dim fs As System.IO.FileStream
fs = New System.IO.FileStream(TextBoxTargetFile.Text, IO.FileMode.
OpenOrCreate)
fs.Seek(0, System.IO.SeekOrigin.End)
fs.Write(ret.return, 0, ret.return.Length())
fs.Close()
MessageBox.Show("Finished!", "Info")
End Sub
End Class