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?