We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Suggestion for replacing some text with a text field in a PDF form?

Hello,

I’d like to ask for your input on a project I’m working on to see if it’s even feasible.

I’m converting a Word document to PDF, which is working great. In the output PDF, I’d like to locate some text (or something else) and insert a Text Field at that position. (The idea being that I’d like the output PDF to have some required fields at various locations in the document.)

I’ve looked in the documentation and seen a ReplaceText method (I’m using the latest .NET version), and it looks like perhaps that might allow me to locate the desired text and remove the text. However, I’m not sure how I could go about inserting a field at that location.

If you all have any suggestions I’d appreciate it.

Mike

Hi Mike,

Thank you very much for considering Aspose.

First of all, you can add a text field in a pdf document using Aspose.Pdf.Kit.FormEditor class. It provides a method called AddField, which allows you to add a field at a specified position on the page. You can find the details here:

http://www.aspose.com/documentation/file-format-components/aspose.pdf.kit-for-.net-and-java/aspose.pdf.kit.formeditor.html

Secondly, you're right, you can replace the existing text using ReplaceText method. However, in order to place the control at that position you'll have to get the position; you can get the Top and Left coordinates of any object in the document. A code snippet is given below to give you an idea to navigate through the objects and then get the Top and Left values:

foreach (Aspose.Pdf.Section sec in pdf1.Sections)
{
foreach (Aspose.Pdf.Paragraph para in sec.Paragraphs)
{
float i = para.Top;
float j = para.Left;
}
}
I hope this helps, if you have any confusion, or some more questions, please do let us know.
Regards,


Thanks for the suggestion, Shahzad. I’ll see if I can get this to work!

Mike

I have a really simple question. Say I have a new PDF that exists only in a MemoryStream.

I’d like to use Aspose.PDF to use the example code you gave to spin through each of the sections and paragraphs.

When I use the following, it doesn’t appear that I can access the sections and paragraphs (something about direct-to-file mode?)
PDF pdf = new PDF(ms);

Do I need to save the PDF to disk first? If so, I don’t see a way to use PDF to access the file, only PDF.Kit.

Thanks for a little more guidance.
Mike

Hi Mike,

You're right, the code snippet can be used with Aspose.Pdf. Please spare us sometime so we could figure out some solution or workaround to see if this problem can be resolved using Aspose.Pdf.Kit.

We appreciate your patience.

Regards,

Hi Mike,

Afer further discussing and investigating about your requirement, we find it is very difficult to support replacing text with a text field or fetching the position of the text. And I am sorry to tell you that the features you required could not be implemented in short time.

Thanks,

Thank you for your consideration Felix. I have found a work-around that will be fine.

Mike