Allow page extraction in a password security pdf with itextsharp

天涯浪子 提交于 2019-12-10 17:39:39

问题


I don't know if it is possible to create a pdf with password security enabled, that also allows extraction of pages.

I havn't found any property in itextsharp which will allow enable page extraction.

Any one has any idea?

This is the property that i would like to enable.

Thank you very much.


回答1:


I've taken a look at the permission bits in the draft of ISO-32000-2 and I've compared them with the parameters (written in ALL_CAPS) available in iText:

bit 1:  Not assigned
bit 2:  Not assigned
bit 3:  Degraded printing: ALLOW_DEGRADED_PRINTING
bit 4:  Modify contents: ALLOW_MODIFY_CONTENTS
bit 5:  Extract text / graphics: ALLOW_COPY
bit 6:  Add / Modify text annotations: ALLOW_MODIFY_ANNOTATIONS
bit 7:  Not assigned
bit 8:  Not assigned
bit 9:  Fill in fields: ALLOW_FILL_IN
bit 10: **Deprecated** ALLOW_SCREEN_READERS
bit 11: Assembly: ALLOW_ASSEMBLY
bit 12: Printing: ALLOW_PRINTING

When I compare the spec with your screen shot, I assume that the permissions are as follows:

  • Printing: ALLOW_DEGRADED_PRINTING or ALLOW_PRINTING
  • Changing the document: ALLOW_MODIFY_CONTENTS
  • Commenting: ALLOW_MODIFY_ANNOTATIONS
  • Form Field Fill-in or Signing: ALLOW_FILL_IN
  • Document Assembly: ALLOW_ASSEMBLY
  • Content copying: ALLOW_COPY
  • Content Accessibility Enabled: ALLOW_SCREENREADERS

I can't find any permission bit that refers to page extraction. I have tried setting all the flags that are documented in ISO-32000-2, but they didn't result in setting the Page Extraction to Allowed.

I have tried two things:

First I tried setting the bits that aren't assigned: bit 1, 2, 7, 8, 13, 14. This didn't change anything. Then I opened a test document in Acrobat and I tried finding a setting that would allow page extraction:

I couldn't find any.

As the permission isn't described in ISO-32000 and as there doesn't seem to be a way to set this permission in Acrobat, I'm inclined to believe that there is no way to set this permission. The only way to see "Allowed", is to open the document with the owner password.

Please update your question as soon as you find a way to set this permission with Acrobat. I'm using Acrobat XI Pro.

On another note: setting the permissions the way you do (using only an owner password and without a user password) is only a psychological, NOT a full-proof technical way to enforce protection. See How to read PDFs created with an unknown random owner password? to find out how to remove permissions from a PDF that is only protected using an owner password.




回答2:


To secure a PDF file using iTextSharp, while allowing the users to extract text and images, but stop them from editing, saving and printing the PDF file, I do this -

//Obviously, use the correct namespace
using iTextSharp.text.pdf;


//Create an instance of PdfReader, associate your PDF file
PdfReader reader = new PdfReader(“yourFile.PDF”);

//Secure your file with a password(yourPDFpassword), set the security to
// PdfWriter.ALLOW_COPY – to allow for security with content extraction

PdfEncryptor.Encrypt(reader, output, true, "", yourPDFpassword, PdfWriter.ALLOW_COPY);


来源:https://stackoverflow.com/questions/25783530/allow-page-extraction-in-a-password-security-pdf-with-itextsharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!