UiPath Documentation
activities
latest
false
Importante :
A tradução automática foi aplicada parcialmente neste conteúdo. A localização de um conteúdo recém-publicado pode levar de 1 a 2 semanas para ficar disponível.
UiPath logo, featuring letters U and I in white

Atividades do Document Understanding

Última atualização 22 de abr de 2026

Leitura de arquivos PDF

Você pode ler e extrair separadamente o conteúdo de arquivos .pdf usando atividades que podem ler todos os caracteres incluídos no documento.

Dependendo de suas necessidades, você pode usar uma atividade simples que pode reconhecer os personagens ou usar um mecanismo de OCR. Os benefícios de usar um mecanismo de OCR são que a leitura do documento pode ser aplicada mesmo em documentos digitalizados, assinados ou manuscritos.

O exemplo abaixo apresenta duas situações de leitura de um arquivo .pdf :

  1. The first one explains how to read the .pdf file while using the Read PDF Text activity.
  2. The second one explains how to read the .pdf file while using the Read PDF With OCR activity. The main difference between the two scenarios is that the second one is also using OCR engines, meaning that the details of extracted information are more accurate than in the first case if the analyzed file is an image, scanned, or includes signed or handwritten fields. You can find both activities in the UiPath.PDF.Activities package.

É necessário apenas um fluxo de trabalho para os dois cenários, comum até o ponto de solicitar ao usuário a escolha do método de leitura desejado.

Etapas
  1. Abra o Studio e crie um Processo.
  2. Add a Flowchart container in the Workflow Designer.
    1. Create a variable named chooseOption, with the GenericValue type, and no default value.
      Observação:

      Add your .pdf files to the project directory in order to be able to run the entire process from the same place or download this example in order to use the given file.

  3. Add an Input Dialog activity and connect it to the Start Node.
    1. No painel Propriedades, adicione a expressão "Choose one option below:" ao campo Rótulo.
    2. Add the expression {"Read PDF Text", "Read PDF With OCR"} in the Options field.
    3. Adicione o valor "Options" ao campo Título.
    4. Adicione a variável chooseOption no campo Resultado.
  4. Add a Flow Decision activity after the Input Dialog activity and connect it to it.
    1. No painel Propriedades, adicione a expressão chooseOption = "Read PDF Text" ao campo Condição.
  5. Add a Sequence container and connect it to the True branch of the Flow Decision activity. The name of the Sequence should be Read PDF Text. This activity extracts information by using regular expressions.
    1. Crie as variáveis exibidas na tabela a seguir:

      Table 1. Variables to be created

      Tipo de VariávelValor Padrão
      extractedTextStringN/A
      arrayTextSystem.String[]N/A
      addressGenericValueN/A
      cityStringN/A
      phoneNumberStringN/A
      invoiceNumberStringN/A
      vendorGenericValueN/A
      bankNameStringN/A
      bankAccountStringN/A
      ibanCodeStringN/A
  6. Add a Sequence container and connect it to the False branch of the Flow Decision activity. The name of the Sequence should be Read PDF With OCR. This activity extracts information by using an OCR engine (Microsoft OCR and Tesseract OCR).
    1. Crie as variáveis exibidas na tabela a seguir:

      Table 2. Variables to be created

      Tipo de VariávelValor Padrão
      extractedTextTesseractStringN/A
      extractedTextMicrosoftStringN/A

      Figure 1. Overview of the beginning of the workflow

      Visão geral do início do fluxo de trabalho

  7. Read a PDF File using the Read PDF Text activity:
    1. Open the Read PDF Text sequence container by double-selecting it.
    2. Add a Read PDF Text activity inside the sequence.
      1. In the Properties panel, add the expression "NPO Invoice.pdf" in the FileName field.
      2. Add the value "All" in the Range field.
      3. Adicione a variável extractedText no campo Texto.
  8. Add an Assign activity after the Read PDF Text activity.
    1. Adicione a variável arrayText no campo Para.
    2. Adicione a expressão extractedText.Split(Environment.NewLine.ToArray, StringSplitOptions.RemoveEmptyEntries) no campo Valor.
  9. Adicione uma atividade If abaixo da atividade Assign.
    1. Adicione a expressão arrayText(0).Equals("Tiefland Glass AG") no campo Condição.
  10. Adicione uma atividade Atribuir dentro do contêiner da Sequência.
    1. Adicione a variável address no campo Para.
    2. Adicione a expressão arrayText(2) no campo Valor.
  11. Add another Assign activity and place it after the previous one.
    1. Adicione a variável city no campo Para.
    2. Adicione a expressão arrayText(3).Split(","c)(0) no campo Valor.
  12. Add another Assign activity and place it after the previous one.
    1. Adicione a variável phoneNumber no campo Para.
    2. Adicione a expressão arrayText(4).Split(":"c)(1).Split({"INVOICE"},StringSplitOptions.None)(0) no campo Valor.
  13. Add another Assign activity and place it after the previous one.
    1. Adicione a variável invoiceNumber no campo Para.
    2. Adicione a expressão arrayText(4).Split(":"c)(1).Split({"INVOICE"},StringSplitOptions.None)(1).Split("#"c)(1) no campo Valor.
  14. Add another Assign activity and place it after the previous one.
    1. Adicione a variável vendor no campo Para.
    2. Adicione a expressão arrayText(arrayText.Count-5) no campo Valor.
  15. Add an Assign activity inside the Else field.
    1. Adicione a variável address no campo Para.
    2. Adicione a expressão arrayText(1) no campo Valor.
  16. Add another Assign activity and place it after the previous one.
    1. Adicione a variável city no campo Para.
    2. Adicione a expressão arrayText(2).Split(","c)(0) no campo Valor.
  17. Add another Assign activity and place it after the previous one.
    1. Adicione a variável phoneNumber no campo Para.
    2. Adicione a expressão arrayText(3).Split(":"c)(1).Split({"INVOICE"},StringSplitOptions.None)(0) no campo Valor.
  18. Add another Assign activity and place it after the previous one.
    1. Adicione a variável invoiceNumber no campo Para.
    2. Adicione a expressão arrayText(3).Split(":"c)(1).Split({"INVOICE"},StringSplitOptions.None)(1).Split("#"c)(1) no campo Valor.
  19. Add another Assign activity and place it after the previous one.
    1. Adicione a variável vendor no campo Para.

    2. Adicione a expressão arrayText(arrayText.Count-5) no campo Valor.

      Figure 2. Overview of the sequence containing the Assign activities

      Visão geral da sequência que contém as atividades Assign

  20. Place a For Each activity after the If container.
    1. Add the variable arrayText in the Value field.
  21. Add an If activity inside the Body container of the For Each activity.
    1. Adicione a expressão item.Contains("Bank Name:") no campo Condição.
  22. Add an Assign activity inside the Then field.
    1. Adicione a variável bankName no campo Para.
    2. Adicione a expressão item.Split(":"c)(1) no campo Valor.
  23. Add an If activity after the previous one.
    1. Adicione a expressão item.Contains("Bank Account:") no campo Condição.
  24. Add an Assign activity inside the Then field.
    1. Adicione a variável bankName no campo Para.
    2. Adicione a expressão item.Split(":"c)(1) no campo Valor.
  25. Add an If activity after the previous one.
    1. Adicione a expressão item.contains("IBAN Code:") no campo Condição.
  26. Add an Assign activity inside the Then field.
    1. Adicione a variável ibanCode no campo Para.

    2. Adicione a expressão item.Split(":"c)(1) no campo Valor.

      Figure 3. Overview of the For Each activity

      Visão geral da atividade For Each

  27. Return to the Read PDF Text sequence and add a Write Text File activity below the For Each activity.
    1. Add the value"InvoiceDetails.txt" in the FileName field.

    2. Adicione a expressão "Invoice details"+Environment.NewLine+Environment.NewLine+"Vendor: "+vendor+Environment.NewLine+"Vendor address: "+address+Environment.NewLine+"City: "+city+Environment.NewLine+"Phone number:"+phoneNumber+Environment.NewLine+"Invoice number:"+invoiceNumber+Environment.NewLine+"Bank name:"+bankName+Environment.NewLine+"Bank account:"+bankAccount+Environment.NewLine+"IBAN Code:"+ibanCode no campo Texto.

      Figure 4. Overview of the For Each container

      Visão geral do contêiner For Each

  28. Return to the Main workflow working area.
  29. Read a PDF File using the Read PDF with OCR activity.
    1. Open the Read PDF With OCR sequence container.
    2. Drag a Read PDF With OCR activity inside the sequence.
      1. Add the value "Invoice02.pdf" in the FileName field.
      2. In the Properties panel, add the value 1 in the DegreeOfParallelism field.
    3. Drag the Google OCR engine inside the Read PDF With OCR activity.
      1. No painel Propriedades, adicione a variável extractedTextTesseract ao campo Texto.
    4. Drag another Read PDF With OCR activity and place it after the previous one.
      1. Add the value "Invoice02.pdf" in the FileName field.
      2. In the Properties panel, add the value 1 in the DegreeOfParallelism field.
    5. Drag the Microsoft OCR engine inside the Read PDF With OCR activity.
      1. In the Properties panel add the variable extractedTextMicrosoft in the Text field.
    6. Drag a Write Text File activity below the Read PDF With OCR activity.
      1. Add the value "OCRMicrosoft.txt" in the FileName field.
      2. Adicione a variável extractedTextMicrosoft no campo Texto.
    7. Drag a Write Text File activity below the previous Write Text File activity.
      1. Add the value "OCRTesseract.txt" in the FileName field.

      2. Adicione a variável extractedTextTesseract no campo Texto.

        Figure 5. Overview of the Read PDF with OCR activity

        Visão geral da atividade Read PDF with OCR

  30. Execute o processo. O robô extrai os dados usando o processo especificado e salva a saída em um arquivo .txt .

Visit the following link to download the example as a ZIP format: Example.

    Esta página foi útil?

    Conectar

    Precisa de ajuda? Suporte

    Quer aprender? Academia UiPath

    Tem perguntas? Fórum do UiPath

    Fique por dentro das novidades