Read PDF file and replace the text next to particular text and save as PDF again

Requirement :

  1. Read PDF files one by one
  2. Capture the PDF File name
    3.Replace the text next to “Credit Card number” text with *****
  3. save as PDF again (same file name)

PS: Attached Sample PDF
PDFSample1.pdf (206.0 KB)

@Shiva_Nikhil

Hi @Sathish_Kumar_S

I’ve successfully replicated your scenario and generated the solution file. You can find it attached below.

Read PDF file and replace the text next to particular text and save as PDF again.zip (307.0 KB)

Here’s a breakdown of the steps I took to create the workflow:

  1. Determined the page count of the PDF.
  2. Split the PDF into individual pages and processed each one separately.
  3. Used regular expressions to replace credit card number with “*****”
  4. Saved the modified content as a text document.
  5. Used Word Activities to convert the text document back into a PDF format.
  6. Merged all the individual PDF pages back together.
  7. Stored the final result in the OUTPUT folder.

Hope it helps you out!

1 Like

Hi @Sathish_Kumar_S

Sequence
PDFFilePath = “path_to_your_PDF_file”
PDFContent = Read PDF Text (PDFFilePath)
FileNameWithoutExtension = Path.GetFileNameWithoutExtension(PDFFilePath)
ModifiedContent = Regex.Replace(PDFContent, “(?<=Credit Card number:\s*)(\d{4}\s\d{4}\s\d{4}\s\d{4})”, “**** **** **** ****”)
Write Text File (FileNameWithoutExtension + “_Modified.pdf”, ModifiedContent)

Sorry the input pdf file is Scanned PDF… Is this logic will work?

I am able to read scanned pdf using read pdf ocr… but the format is changing after saved as text file.

Is it possible to keep the output PDF as same as input pdf file format?

Hi @Sathish_Kumar_S

Yes you can implement it using "Read PDF with OCR " activity

Please find the below workflow updated according to your requirement
Read PDF file and replace the text next to particular text and save as PDF again.zip (429.2 KB)

Hope it helps you out!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.