Forum Discussion

Jyotiprakash's avatar
Occasional Contributor
2 years ago

How to use external libraries packages in testcomplete

I am using iTextSharp libraries to read font size of pdf. I am using the below code. I have downloaded the itextSharp package and i have integrated it in my project in the following manner( right click on project then selecting add and then exisiting item and selecting those itextSharp files). I have copied these files stored it in smartbear bin folder too. But I am getting error like  "ActiveX component can't create object: 'iTextSharp.text.PdfReader' ".



Sub font()

Dim pdfReader
Set pdfReader = CreateObject("iTextSharp.text.pdf.PdfReader") 
pdfReader.Open "C:\path\to\your\pdf\file.pdf"

' Loop through each page of the PDF file
For i = 1 To pdfReader.NumberOfPages
' Get the page object
Set page = pdfReader.GetPageN(i)
' Get the content stream for the page
Set content = page.GetAsArray(PdfName.CONTENTS)
' Loop through each element in the content stream
For Each element In content
' Check if the element is a text object
If element.IsArray() And element.GetAsName(0) = PdfName.TEXT Then
' Get the font object for the text object
Set font = element.GetAsArray(0).GetAsDict(PdfName.FONT)
' Get the font name and size
fontName = font.Get(PdfName.BASEFONT).ToString()
fontSize = element.GetAsArray(0).GetAsNumber(1).Value
' Print the font name and size
WScript.Echo "Font Name: " & fontName & " Font Size: " & fontSize
End If

' Close the PdfReader object
End SUb

1 Reply

  • rraghvani's avatar
    Champion Level 3

    The ActiveX component needs to be registered, or the application needs to be installed for other applications to use it.