Link Search Menu Expand Document

Set Word Spacing for Text in PDF - VBScript and VB6

PDF SDK sample in VBScript and VB6 demonstrating ‘Set Word Spacing for Text in PDF’

' This example demonstrates how to change the word spacing.

' Create Bytescout.PDF.Document object
Set pdfDocument = CreateObject("Bytescout.PDF.Document")
pdfDocument.RegistrationName = "demo"
pdfDocument.RegistrationKey = "demo"

' If you wish to load an existing document uncomment the line below And comment the Add page section instead
' pdfDocument.Load("existing_document.pdf")

Set comHelpers = pdfDocument.ComHelpers

' Add page
Set page1 = comHelpers.CreatePage(comHelpers.PAPERFORMAT_A4)

Set canvas = page1.Canvas

Set font = comHelpers.CreateSystemFont("Arial", 16)
Set brush = comHelpers.CreateSolidBrush(comHelpers.CreateColorGray(0))
Set stringFormat = comHelpers.CreateStringFormat()

' Standard word spacing
stringFormat.WordSpacing = 0.0
canvas.DrawString_4 "Standard word spacing 0.0", (font), (brush), 20, 20, (stringFormat)

' Increased word spacing
stringFormat.WordSpacing = 5.0
canvas.DrawString_4 "Increased word spacing 5.0", (font), (brush), 20, 50, (stringFormat)

' Reduced word spacing
stringFormat.WordSpacing = -2.5
canvas.DrawString_4 "Reduced word spacing -2.5", (font), (brush), 20, 80, (stringFormat)

' Save document to file

' Open document in default PDF viewer app
Set shell = CreateObject("WScript.Shell")
shell.Run "result.pdf", 1, false

Download Source Code (.zip)

Return to the previous page Explore PDF SDK