Free Support Forum - aspose.com

Form Fields with same Name


#1

Hello, I have a pdf with many form fields that have the same name.
2 questions:

  1. Is it possible to obtain the collection of all the fields?
  2. The location does not belong to any of the form fields

This my code:

     string ruta1 = @"C:\\borrar\\pruebaPdf.pdf";
        string ruta2 = @"C:\\borrar\\pruebaPdf_SALIDA.pdf";
        Document opdf = new Document(ruta1);

        
        MessageBox.Show("Encontrado " + opdf.Form.Fields.Length.ToString() + " formularios");
        Aspose.Pdf.Forms.TextBoxField campo = opdf.Form.Fields[0] as Aspose.Pdf.Forms.TextBoxField;

        TextFragment textFragment = new TextFragment("(LOCALIZADO)");
        textFragment.Position = new Position(campo.Rect.LLX, campo.Rect.LLY);
        textFragment.TextState.FontSize = 12;
        textFragment.TextState.Font = FontRepository.FindFont("TimesNewRoman");
        textFragment.TextState.BackgroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray);
        textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Red);


        TextBuilder textBuilder = new TextBuilder(opdf.Pages[campo.PageIndex]);
        // Append the text fragment to the PDF page
        textBuilder.AppendText(textFragment);

        opdf.Save(ruta2);

        System.Diagnostics.Process.Start(ruta2);

PRUEBAPDF.pdf (3.5 KB)

Thank you!


#2

@sgrsoft

We were able to notice in our environment while using Aspose.PDF for .NET 19.5 that API is not extracting all text boxes from your PDF. However, could you please explain a bit more about your original requirements. By looking at your code snippet, it seems like you want to get location of text box so that you can place a TextFragment against it. In case our understandings are correct, please confirm. We will further proceed accordingly.