NielMichaelBantilan-0484 avatar image
0 Votes"
NielMichaelBantilan-0484 asked JackJJun-MSFT commented

Printing over a scan image

Hi! Good Day Everyone
I'm not really a hardcore developer, so I have been hoping somebody could help me out on my simple tool that I am trying to create.
So it's like this We have this pre made scholarship vouchers that I need to fill out some details like names, address etc.
I wanted to create a simple tool where I will just input the details and it will print the details to the corresponding fields
I tried using the following codes and hoping to hit the mark where I need those details but I this is not the best way. Hoping somebody can guide me . Thank You.

using (Font font1 = new Font("Arial", 24, FontStyle.Bold, GraphicsUnit.Pixel))
PointF pointf1 = new PointF(30, 1000);
e.Graphics.DrawString(textBox1.Text, font1, Brushes.Blue, pointf1);


dummy.jpg (303.4 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@NielMichaelBantilan-0484 ,May I know if you have got any chance to check my answer? I am glad to help if you have any others questions.

0 Votes 0 ·

1 Answer

JackJJun-MSFT avatar image
0 Votes"
JackJJun-MSFT answered

@NielMichaelBantilan-0484 , If you want to fill the details to the correspond fields into the pdf file, it will be better for you to create a pdf file that contains the text fields.

The following link shows that how to use itextsharp to create a TextField on an existing PDF.

Using iTextSharp to create a TextField on an existing PDF

After creating the pdf, you could try the following code to get fields and set the field's value.


 private void button1_Click(object sender, EventArgs e)
         private void ListFieldNames()
             string pdfTemplate = @"D:\ExampleWithFileds.pdf"; 
             this.Text += " - " + pdfTemplate;
             PdfReader pdfReader = new PdfReader(pdfTemplate);
             StringBuilder sb = new StringBuilder();
             foreach (var de in pdfReader.AcroFields.Fields)
                 sb.Append(de.Key.ToString() + Environment.NewLine);
             richTextBox1.Text = sb.ToString();
         private void FillForm()
             string pdfTemplate = @"D:\ExampleWithFileds.pdf";
             string newFile = @"D:\ExampleWithFileds111.pdf"; ;
             PdfReader pdfReader = new PdfReader(pdfTemplate);
             PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(newFile, FileMode.Create));
             AcroFields pdfFormFields = pdfStamper.AcroFields; 
             pdfFormFields.SetField("Given Name Text Box", "jack");
             pdfFormFields.SetField("Family Name Text Box", "father");
             pdfFormFields.SetField("Address 1 Text Box", "home");
             pdfFormFields.SetField("House nr Text Box", "house");
             pdfStamper.FormFlattening = false;

Note: Please install nuget-package iTextSharp to use the above code.



If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

image.png (77.7 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.