Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Wed Aug 19, 2015 2:04 am

Hello guys,

I am now writing a project for my work. Here are the details:

I will have a template pdf file such as a contract. In the contract I will leave some blanks for filling, such as contractor: _______.

Now I am writing a project based on .Net C# winform to automatically fulfill the blanks in the pdf file. I need to find the key word such as contractor and then fulfill the blank using the string that I have input in the winform input box.

I would like to use spire.PDF. Is there any one who can advise what function I can use to archive this target?

Thanks very much!

hachi1030
 
Posts: 5
Joined: Wed Aug 19, 2015 1:58 am

Wed Aug 19, 2015 6:02 am

Hello,

Thanks for your inquiry.
You can use the FormField to archive this target.
There is the tutorial in our website about how to create FormField in your template pdf file.
http://www.e-iceblue.com/Tutorials/Spire.PDF/Spire.PDF-Program-Guide/C-/VB.NET-Create-FormField-in-PDF.html
And here is the tutorial about how to fill FormFields in PDF File.
http://www.e-iceblue.com/Tutorials/Spire.PDF/Spire.PDF-Program-Guide/PDF-FormField/Fill-Form-Fields-in-PDF-File-with-C.html
Please feel free to contact us if you have any problems.

Best Regards,
Sweety

E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Wed Aug 19, 2015 6:30 am

Great, thanks. I have read these 2 articles before. I would like to ask can I separate the form elements into the contract to make it like a contract not a form? Also, can I modify the css of the form to make it as a blank not a input box?

hachi1030
 
Posts: 5
Joined: Wed Aug 19, 2015 1:58 am

Wed Aug 19, 2015 9:24 am

Hello,

Thanks for your reply.
Suppose you already have the template pdf file. I recommend you to find the key word first, then find the position. Finally, you can draw the text directly in the position.
Here is the code for your reference.
Code: Select all
 PdfDocument pdf = new PdfDocument();
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;
            PdfPageBase page = pdf.Pages.Add();
            PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 12f);
            PdfSolidBrush brush = new PdfSolidBrush(Color.Black);
            PdfPen pen = PdfPens.Black;
            string label = "contractor:";
            float x = 0;
            float y = 10;
            page.Canvas.DrawString(label, font, brush, x, y);
            float width = font.MeasureString(label).Width;
            float height = font.MeasureString(label).Height;
            x = x + width + 3;
            y = y + height;
            float lineEndx = 130;
            page.Canvas.DrawLine(pen, x, y, lineEndx, y);
            pdf.SaveToFile("5635.pdf");
            PdfDocument pdf1 = new PdfDocument("5635.pdf");
            PdfTextFind[] result1 = null;
            result1 = pdf1.Pages[0].FindText("contractor").Finds;
            foreach (PdfTextFind find in result1)
            {
                float Textx = find.Position.X + width+3;
                float texty = find.Position.Y-2;
                pdf1.Pages[0].Canvas.DrawString("your input", font, brush, Textx, texty);
                break;
            }
            pdf1.SaveToFile("5635-1.pdf");   


Best Regards,
Sweety

E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Fri Aug 21, 2015 6:34 am

sweety1 wrote:Hello,

Thanks for your reply.
Suppose you already have the template pdf file. I recommend you to find the key word first, then find the position. Finally, you can draw the text directly in the position.
Here is the code for your reference.
Code: Select all
 PdfDocument pdf = new PdfDocument();
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;
            PdfPageBase page = pdf.Pages.Add();
            PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 12f);
            PdfSolidBrush brush = new PdfSolidBrush(Color.Black);
            PdfPen pen = PdfPens.Black;
            string label = "contractor:";
            float x = 0;
            float y = 10;
            page.Canvas.DrawString(label, font, brush, x, y);
            float width = font.MeasureString(label).Width;
            float height = font.MeasureString(label).Height;
            x = x + width + 3;
            y = y + height;
            float lineEndx = 130;
            page.Canvas.DrawLine(pen, x, y, lineEndx, y);
            pdf.SaveToFile("5635.pdf");
            PdfDocument pdf1 = new PdfDocument("5635.pdf");
            PdfTextFind[] result1 = null;
            result1 = pdf1.Pages[0].FindText("contractor").Finds;
            foreach (PdfTextFind find in result1)
            {
                float Textx = find.Position.X + width+3;
                float texty = find.Position.Y-2;
                pdf1.Pages[0].Canvas.DrawString("your input", font, brush, Textx, texty);
                break;
            }
            pdf1.SaveToFile("5635-1.pdf");   


Best Regards,
Sweety

E-iceblue support team


Great, this code will help a lot! I am trying to draw the string. Also, I assume that I can put a form input field appending to a text and operate that too right?

Another question, whenever I create a new pdf file, there will be red string in the top which is "Evaluation Warning : The document was created with Spire.PDF for .NET.". Can I do some settings to make sure that this string will not be added into my pdf whenever I create a new pdf?

hachi1030
 
Posts: 5
Joined: Wed Aug 19, 2015 1:58 am

Fri Aug 21, 2015 7:57 am

Hello,

Thanks for your reply.
1. Yes.
2. You could contact our sales team(sales@e-iceblue.com) to get a temporary license file to remove the warning message and have a better evalution on our products.

Best Regards,
Sweety

E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Return to Spire.PDF