PDF In-Depth

UNICODE to ANSI converter

February 01, 2000

Advertisement
Advertisement
 

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 
' 
'COMMENTS 
'======== 
'Please email comments to walt@brookhouse.co.uk 
' 
'WHAT DOES IT DO 
'=============== 
'* Useful routine for converting UNICODE strings to 'readable' ANSI 
'* It was designed for decoding UNICODE strings in PDF files 
' 
'RESTRICTIONS 
'============ 
'* 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" & 

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

n%
                        loops% = loops% + 

1
                End If
       Next
    
       For i% = 0 To UBound(myArray) - 1
                ansiStr$ = ansStr$ & Chr(myArray(i%))
       Next
    
       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

Back to the past, 15 years ago! Open Publish 2002

Looking back to 2002, it's amazing how much of the prediction became a reality. Take a read and see what you think!

September 14, 2017
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.

Features

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.