how to Add Input Text Field to Pdf (AcroForm) with PDFSharp
Asked Answered
D

2

0

it's should be simple but i couldn't find the answer anywhere in google or the source documentation.

someone have asked the same question 4 years ago, but still no one answered!

if it's not possible. can someone please confirm, so that i can find another pdf generator library that can do that. because it's very important in my case to be able to generate pdf with input capability

thanks!

Dismantle answered 9/10, 2018 at 9:24 Comment(3)
Methinks it should work, but I cannot provide sample code (now).Practise
please do when you have the time, i'm running out of option for opensource pdf generator library for c#. so i really hopes pdfSharp can do thisDismantle
I would refer you to this question as it is similar to yours.Ambit
A
-1

See my post here with Links on how to to add text to an existing field and also how to add a field to a PDF document using PDFsharp.

Additament answered 19/12, 2022 at 17:22 Comment(0)
F
-6

We will go through the step by step

  1. First you need to create object of PdfReader
    • PdfReader pdfReader = new PdfReader(templatePath); here "templatePath" is the template(sample file) where you write your all data
  2. Then create source file where all data is rendered(write)
    • System.IO.Directory.CreateDirectory(Server.MapPath(DocPath)); "DocPath" is the path where output file is save
  3. Then Initialize PdfStamper and AcroFields object :

    PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(Server.MapPath(newFile), FileMode.Create));
    AcroFields pdfFormFields = pdfStamper.AcroFields;
    
  4. Then set Field in PDF :

        pdfFormFields.SetField("this text should field name in PDF(template PDF)", "Actual value you want to write");
    
  5. Dispose all objects

        pdfStamper.FormFlattening = true;
        pdfStamper.Close();
        pdfReader.Close();
    
Forethoughtful answered 9/10, 2018 at 9:47 Comment(4)
Good that the code is working, but it does not answer the question.Practise
are you sure its for pdfSharp? because i cant find pdfStamper in the libraryDismantle
The answer is not for PDFsharp, that's why it does not answer the question.Practise
@IlikedtheoldStackOverflow any knowledge of whether it is possible to be done?Ambit

© 2022 - 2024 — McMap. All rights reserved.