0

I have an Acroform PDF (a PDF which can be edited) but I'm using an API to sign the PDF which requires that the PDF is a normal one and never an Acroform one.

Is there any way to transform an AcroForm PDF to a normal one?

I tried making it Read-Only but even though it cannot be edited it still is an Acroform PDF.

JasonWilczak
  • 2,303
  • 2
  • 21
  • 37
Miquel Coll
  • 759
  • 15
  • 49
  • I believe you have to flatten the form, let me double check. – JasonWilczak Jul 08 '15 at 12:43
  • A PDF with AcroForm form fields ***is** a normal one*. What you call an *Acroform PDF* most likely is a PDF with AcroForm fields which has been *Reader-enabled*, i.e. which contains usage rights signatures. Usage rights signature also are normal PDFs but some simple signing APIs may have trouble with previously signed PDFs. – mkl Jul 08 '15 at 21:56

1 Answers1

2

In answer to my comment, I assume you are using iTextSharp, even though you do not specify. Using iTextSharp, I believe you need to Flatten the form when you are done. Here is a simple example:

public void GeneratePDF(string filePath, List<PDFField> modifiedFields)
        {
            var pdfReader = new PdfReader(filePath);
            var folderStructure = filePath.Split('\\');
            if (folderStructure.Length == 0) return;
            var currentFileName = folderStructure.Last();
            var newFilePath = string.Format("{0}{1}", Constants.SaveFormsPath,
                currentFileName.Replace(".pdf", DateTime.Now.ToString("MMddyyhhmmss") + ".pdf"));
            var pdfStamper = new PdfStamper(pdfReader, new FileStream(newFilePath, FileMode.Create));
            foreach (var field in modifiedFields.Where(f=>f.Value != null))
            {
                pdfStamper.AcroFields.SetField(field.Name, field.Value);
            }
            pdfStamper.FormFlattening = true;
            pdfStamper.Close();
        }

Ignoring the parts about the filename, it boils down to passing in some key value list regarding the field values to set. This could be where you do your signature piece, and then setting the FormFlattening property on the stamper to true.

Here is another SO post where they used a similiar technique for a slightly different issue, it may be of help: How to flatten already filled out PDF form using iTextSharp

Community
  • 1
  • 1
JasonWilczak
  • 2,303
  • 2
  • 21
  • 37