PDF In-Depth

UNICODE to ANSI converter

February 01, 2000


Roy from Brook House Publishing has kindly submitted a VB procedure for converting UNICODE to ANSI. "I wrote it for parsing UNICODE strings in PDF. A bit specialised maybe, but useful nonetheless. Well it was for me anyway:)"

This code sample is posted here for the general benefit of the PDF development community. Attribution and usage guidelines are as noted in the code source; please respect the wishes of the author when using this code.

'©2000 Roy Walter, Brook House Ltd 
'Please email comments to walt@brookhouse.co.uk 
'* Useful routine for converting UNICODE strings to 'readable' ANSI 
'* It was designed for decoding UNICODE strings in PDF files 
'* You can use it and modify it but you can't sell it 
'* If you redistribute do not remove this line and the lines above 
Sub UnicodeToAnsi()  

Dim hx, myArray 
Dim c$, ansiStr$, uniStr$ 
Dim arrSize%, i%, loops%, n%  

       'example only 
       uniStr$ = "" 
       If InStr(uniStr$, "feff") = 0 Then Exit Sub    'it's not unicode! 

       If Left(uniStr$, 1) = "<" Then uniStr$ = Mid(uniStr$, 2)
       If Right(uniStr$, 1) = ">" Then
                uniStr$ = Left(uniStr$, Len(uniStr$) - 1)
       End If

       i% = Len(uniStr$)
       arrSize% = i% / 4
       ReDim myArray(arrSize%)
       For i% = 1 To Len(uniStr$) Step 4
                c$ = Mid$(uniStr$, i, 4)
                If c$ <> "feff" Then
                        hx = "&H" & 

                        n% = Int(hx)
                        myArray(loops%) = 

                        loops% = loops% + 

                End If
       For i% = 0 To UBound(myArray) - 1
                ansiStr$ = ansStr$ & Chr(myArray(i%))
       MsgBox ansiStr$
End Sub
PDF In-Depth Free Product Trials Ubiquitous PDF

Debenu Quick PDF Library

Get products to market faster with this amazing PDF developer SDK. Over 900 functions and an equally...

Download free demo

Five visions of a PDF Day

In the world of PDFs or as we like to say Planet (of) PDF, a year isn't a real PDF year without an intense few days of industry knowledge sharing.

May 15, 2018
Platinum Sponsor

Search Planet PDF
more searching options...
Planet PDF Newsletter
Most Popular Articles
Featured Product

Debenu PDF Aerialist

The ultimate plug-in for Adobe Acrobat. Advanced splitting, merging, stamping, bookmarking, and link control. Take Acrobat to the next level.


Adding a PDF Stamp Comment

OK, so you want to stamp your document. Maybe you need to give reviewers some advice about the document's status or sensitivity. This tip from author Ted Padova demonstrates how to add stamps with the Stamp Tool along with related comments.