Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8784725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:10:23+00:00 2026-06-13T21:10:23+00:00

We have a library of PDF forms that contain fillable fields and that can

  • 0

We have a library of PDF forms that contain fillable fields and that can be opened in Adobe Reader and filled out by our end users. Note that we are NOT generating PDFs but simply using existing PDFs. All of these forms are protected against editing non-fillable fields in Acrobat by means of a password.

The problem is that when we open the PDF in our code to prefill some of the fields the password protection is lost and the form that is served up is editable in Acrobat.

So:

  1. Is there a way to prefill fillable fields using iTextSharp without unlocking the PDF and the resulting output stream?
  2. Is there a way to relock the form while still allowing an end user
    to open in Reader, fill fillable fields, print, etc., without
    requiring a password?

Here is a simplified example of the code we are currently using. We have tried locking the output stream (code not currently available) but the file could not then Reader prompted the user for a password.

System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
Byte[] password = encoding.GetBytes("secretPassword");
PdfReader reader = null;
MemoryStream outputStream = null;
PdfStamper stamper = null;
pdfStream.Seek(0, SeekOrigin.Begin);
reader = new PdfReader(pdfStream, password);
outputStream = new MemoryStream();
stamper = new PdfStamper(reader, outputStream);

AcroFields fields = stamper.AcroFields;
fields.SetField("prefillField1", "Some text");
stamper.Close();
outputStream.Close();
reader.Close();
// outputStream sent to user/browser. PDF opens in Reader, but the form can be opened in 
// Acrobat without a password and edited.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T21:10:24+00:00Added an answer on June 13, 2026 at 9:10 pm

    You cannot edit a PDF if it is password protected. You will like you are doing have to open it with the password to edit it. With that it looks like you are creating a copy of that document and presenting to the user. You can encrypt the PDF with an edit password. Here is a copy of a method that I found that I use with itextsharp. If you set the editPassword while leaving the openPassword null then your users should be able to view the pdf and interact with it but won’t be able to edit it based on the permissions you set. Hope this helps.

        /// <summary>
        /// Adds the given Open (User) and Edit (Owner) password to the PDF and optionally sets
        /// the various Allow/Not Allowed restrictions
        /// </summary>
        /// <param name="openPassword">Open/User password</param>
        /// <param name="editPassword">Edit/Owner password</param>
        /// <param name="allowAssemply">Assembly means merging, extracting, etc the PDF pages</param>
        /// <param name="allowCopy">Copy means right-click copying the content of the PDF to the system</param>
        /// <param name="allowDegradedPrinting">Can print low quality version of the PDF</param>
        /// <param name="allowFillIn">Can insert data into any AcroForms in the PDF</param>
        /// <param name="allowModifyAnnotations">Modification of any annotations</param>
        /// <param name="allowModifyContents">Modification of any content in the PDF</param>
        /// <param name="allowPrinting">Allows printing at any quality level</param>
        /// <param name="allowScreenReaders">Allows the content to be parsed/repurposed for screen readers</param>
        public byte[] GetEncryptedPDF(byte[] pdf,
             string openPassword, string editPassword,
             bool allowAssemply, bool allowCopy,
             bool allowDegradedPrinting, bool allowFillIn,
             bool allowModifyAnnotations, bool allowModifyContents,
             bool allowPrinting, bool allowScreenReaders)
        {
            int permissions = 0;
            if (allowAssemply) 
                permissions = permissions | PdfWriter.ALLOW_ASSEMBLY;
            if (allowCopy) 
                permissions = permissions | PdfWriter.ALLOW_COPY;
            if (allowDegradedPrinting)  
                permissions = permissions | PdfWriter.ALLOW_DEGRADED_PRINTING; 
            if (allowFillIn) 
                permissions = permissions | PdfWriter.ALLOW_FILL_IN; 
            if (allowModifyAnnotations) 
                permissions = permissions | PdfWriter.ALLOW_MODIFY_ANNOTATIONS; 
            if (allowModifyContents) 
                permissions = permissions | PdfWriter.ALLOW_MODIFY_CONTENTS; 
            if (allowPrinting) 
                permissions = permissions | PdfWriter.ALLOW_PRINTING; 
            if (allowScreenReaders) 
                permissions = permissions | PdfWriter.ALLOW_SCREENREADERS; 
    
            PdfReader reader = new PdfReader(pdf);
            using (MemoryStream memoryStream = new MemoryStream())
            {
                PdfEncryptor.Encrypt(reader, memoryStream, true, openPassword, editPassword, permissions);
                reader.Close();
                return memoryStream.ToArray();
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a library that interacts with our phone system, ie, Hey phone, call
I have PDF forms that I want to autopopulate with data from my Django
I have a method that generates a PDF file using Reportlab library: def obtenerPDFNuevoPedido(self,
Is there any PHP PDF library that can replace placeholder variables in an existing
I have a third-party PDF file with some form fields, that I need to
I have an old project that is using iTextSharp library for PDF generation. iTextSharp
I am working on online pdf library project. In this I have a feature
I have tried mupdf library to render my pdf ie. to have my own
I have a library made in C++/GDI that I am trying to port to
I have a library project that should be the base for several web applications.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.