Link Search Menu Expand Document

Data Masking in PDF - VB.NET

PDF Extractor SDK sample in VB.NET demonstrating ‘Data Masking in PDF’

Imports System.IO
Imports System.Text.RegularExpressions
Imports Bytescout.PDFExtractor

Module Program

    Sub Main()


            ' Generate CSVExtractor instance
            Using extractor As New CSVExtractor("demo", "demo")

                ' Load PDF document

                ' Get all data
                Dim allData = extractor.GetCSV()

                ' Regular expressions and replacements
                Dim ssnRegex = "\d{3}[-]?\d{2}[-]?\d{4}"
                Dim ssnReplace = "***-**-****"

                Dim phoneRegex = "\d{3}[-]?\d{3}[-]?\d{4}"
                Dim phoneReplace = "***-***-****"

                ' Find and mask SSN and phone numbers
                allData = Regex.Replace(allData, ssnRegex, ssnReplace)
                allData = Regex.Replace(allData, phoneRegex, phoneReplace)

                ' Write as CSV
                File.WriteAllText("output.csv", allData)

                ' Open file

            End Using

        Catch ex As Exception
        End Try

        Console.WriteLine("Press enter key to exit...")

    End Sub

End Module

Download Source Code (.zip)

Return to the previous page Explore PDF Extractor SDK

Copyright © 2016 - 2023 ByteScout