Hi, I'd like to loop through and entire doc and verify that no font size smaller than 10 and that only certain font type is used within the doc.
Need VB.Net script.
Kindly help - Thank you!
Shared Sub Main(ByVal args() As String)
Dim fileName As String="sample.docx"
Dim ressult = Verify(fileName)
End Sub
Private Shared Function Verify(ByVal fileName As String) As Boolean
Dim result As Boolean = True
Dim document As New Document()
document.LoadFromFile(fileName)
For Each section As Section In document.Sections
'verify font in body
For Each obj As DocumentObject In section.Body.ChildObjects
If Not VerifyFont(obj, document) Then
result = False
Exit For
End If
Next obj
'verify font in header footer
For Each hf As HeaderFooter In section.HeadersFooters
For Each hfobj As DocumentObject In hf.ChildObjects
If Not VerifyFont(hfobj, document) Then
result = False
Exit For
End If
Next hfobj
Next hf
Next section
Return result
End Function
Private Shared Function VerifyFont(ByVal obj As DocumentObject, ByVal document As Document) As Boolean
Dim result As Boolean=True
'verify font in tables
If obj.DocumentObjectType = DocumentObjectType.Table Then
For Each row As TableRow In (TryCast(obj, Table)).Rows
For Each cell As TableCell In row.Cells
For Each [cobj] As DocumentObject In cell.ChildObjects
If Not VerifyFontInPara([cobj], document) Then
result = False
Exit For
End If
Next [cobj]
Next cell
Next row
End If
'verify font in paragraph
If Not VerifyFontInPara(obj, document) Then
result = False
End If
Return result
End Function
Private Shared Function VerifyFontInPara(ByVal obj As DocumentObject, ByVal document As Document) As Boolean
If obj.DocumentObjectType = DocumentObjectType.Paragraph Then
Dim objs = (TryCast(obj, Paragraph)).ChildObjects
For i As Integer = 0 To objs.Count - 1
If objs(i).DocumentObjectType = DocumentObjectType.TextRange Then
Dim tr As TextRange = TryCast(objs(i), TextRange)
If tr.CharacterFormat.FontSize < 10 OrElse tr.CharacterFormat.FontName <> "certain font1" OrElse tr.CharacterFormat.FontName <> "certain font2" Then
Return False
End If
End If
Next i
End If
Return True
End Function
if (tr.CharacterFormat.FontSize < 11 || tr.CharacterFormat.FontName != "Calibri" || tr.CharacterFormat.FontName != "Arial" || tr.CharacterFormat.FontName != "Times Roman")
if (tr.CharacterFormat.FontSize < 11 || !(tr.CharacterFormat.FontName == "Calibri" || tr.CharacterFormat.FontName == "Arial" || tr.CharacterFormat.FontName == "Times Roman"))