7

I have a fillable, saveable PDF file that has an owner password (that I don't have access to). I can fill it out in Adobe reader, export the FDF file, modify the FDF file, and then import it.

Then I tried to do it with iText for .NET. I can't create a PdfStamper from my PdfReader because I didn't provide the owner password to the reader. Is there any way to do this programmatically or must I recreate the document?

Even using FdfReader requires a PdfStamper. Am I missing anything? Anything legal that is - I'm pretty sure I could hack the document, but I can't. Ironically, recreating it would probably be ok.

Joris Schellekens
  • 8,483
  • 2
  • 23
  • 54
  • iText's security flag support is non-existant. We just check to see whether or not you have the owner password, and throw if you don't. There have been enough complaints along these lines recently that we'll probably end up adding some flag-level security support in the future. – Mark Storer Oct 26 '10 at 00:37

4 Answers4

6

This line will bypass edit password checking in iTextSharp:

PdfReader.unethicalreading = true;
VahidN
  • 18,457
  • 8
  • 73
  • 117
3

[I found this question several months after it was posted and I'm posting this solution now for anyone who comes across this question in a search.]

I was in the exact same situation: my customer had a PDF with fillable fields that I needed to programmatically access. Unfortunately the PDF was password protected and they didn't have the password so I found couldn't work with their file.

What I discovered was that iTextSharp version 4.0.4 (and later) enforces password restrictions, earlier versions did not.

So I downloaded version 4.0.3 and sure enough it worked. In my case I didn't even have to change my code to use this older version.

You can download 4.0.3 (and all other versions) at SourceForge.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Jay Riggs
  • 53,046
  • 9
  • 139
  • 151
  • 1
    You can no longer download versions below 5.0.0 because they have technical and legal issues. And in any case, iTextSharp moved from SourceForge to Github: http://github.com/itext/itextsharp – Amedee Van Gasse Jan 03 '16 at 15:10
2

Two important things

  1. Set PdfReader.unethicalreading = true to prevent BadPasswordException.
  2. Set append mode in PdfStamper's constructor, otherwise the Adobe Reader Extensions signature becomes broken and Adobe Reader will display following message: "This document contained certain rights to enable special features in Adobe Reader. The document has been changed since it was created and these rights are no longer valid. Please contact the author for the original version of this document."

So all you need to do is this:

PdfReader.unethicalreading = true;
using (var pdfReader = new PdfReader("form.pdf"))
{
    using (var outputStream = new FileStream("filled.pdf", FileMode.Create, FileAccess.Write))
    {
        using (var stamper = new iTextSharp.text.pdf.PdfStamper(pdfReader, outputStream, '\0', true))
        {
            stamper.AcroFields.Xfa.FillXfaForm("data.xml");
        }
    }
}

See How to fill XFA form using iText?

Community
  • 1
  • 1
Bohdan
  • 1,987
  • 16
  • 23
0

Unless someone else chimes in, I'll assume the answer is "No"

I wound up regenerating the PDF in an unencrypted form.

CMPalmer
  • 8,571
  • 5
  • 40
  • 49
  • 2
    I posted the question from a customer site using my iPhone and I was in too big of a hurry (or too lazy) to authenticate via OpenID, so I just posted anonymously then forgot to set it to community wiki. – CMPalmer Feb 02 '09 at 04:13