问题设置权限(SetEncryption)在pdf内 [英] Problems setting rights (SetEncryption) within pdf

查看:1945
本文介绍了问题设置权限(SetEncryption)在pdf内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们遇到使用该产品的问题。 iText 5.4.3中的某些功能似乎不能正常运行吗?请问有人可以给我们一个提示如何解决吗?



我们将src.pdf修改为dest.pdf,如下所示:

 函数CreateFlattedPdf(ByRef originalPdf As Byte())As Byte()
Dim retValue As Byte()= Nothing
Dim originalPdfReader As PdfReader = New PdfReader(originalPdf)
Dim pdfKopie As MemoryStream = New MemoryStream()
Dim pdfKopieStamper As PdfStamper = New PdfStamper(originalPdfReader,pdfKopie)

pdfKopieStamper.SetEncryption(False,userPassword,ownerPassword ,_
PdfWriter.ALLOW_ASSEMBLY _
或PdfWriter.ALLOW_COPY _
或PdfWriter.ALLOW_DEGRADED_PRINTING _
或PdfWriter.ALLOW_FILL_IN _
或PdfWriter.ALLOW_MODIFY_ANNOTATIONS _
或PdfWriter.ALLOW_MODIFY_CONTENTS _
或PdfWriter.ALLOW_PRINTING _
或PdfWriter.ALLOW_SCREENREADERS _


'Entferne die Signaturinformationen aus dem original Pdf-Dokument
pdfKopieStamper.FormFlattening = True
pdf $ amper lose lose lose lose $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $
pdfKopie.Close()
originalPdfReader.Close()

返回retValue
结束函数

此外,我们把所有可能的文本权限。因此,我们得到一个PDF,页面提取(页面提取)和文档安排(文档编译)不允许



我的问题是:


  1. 这是iText的不正当行为,还是一般可以用iText改变这个设置?如果是这样,怎么(代码示例)?

  2. 可以将这些权限设置为没有任何密码吗?直到现在,我们只看到设置权限的功能总是与用户和所有者密码一起使用。

感谢您的帮助!



Ingo

解决方案

观察



OP所看到的权限标签确实显示了一些缺失的权限:





检查(不加密它!)一个得到只允许页面提取,一旦您停止加密,即使是允许的。


1这是iText的不正当行为,或者,一般可以用iText改变这个设置?如果是这样,那么如何(代码示例)?


它不是iText 的不正当行为, em> Adob​​e Reader的行为。 Adobe Reader一般限制其功能,只能提升使用权限的文档的限制。这种使用权利只能由Adobe软件应用。


2可以将这些权限设置为没有密码吗?直到现在,我们只看到设置权限的功能总是与用户和所有者的密码一起使用。


使用加密实际上是有效的因为它只能用于删除权限,而不是添加他们。



资源



关于从并行发布在itext-questions邮件列表




  • 一个示例源文件说明问题 src.pdf

  • 由OP代码生成的相应结果文件 dest.pdf

  • 显示OP的屏幕截图的PDF查看器的dest.pdf的权限选项卡:




we run into problems using the product. It seems does some functions in iText 5.4.3 doesn’t working well? Please, can someone give us a hint how to solve that?

We modify src.pdf to dest.pdf as follows:

Function CreateFlattedPdf(ByRef originalPdf As Byte()) As Byte()
    Dim retValue As Byte() = Nothing
    Dim originalPdfReader As PdfReader = New PdfReader(originalPdf)
    Dim pdfKopie As MemoryStream = New MemoryStream()
    Dim pdfKopieStamper As PdfStamper = New PdfStamper(originalPdfReader, pdfKopie)

    pdfKopieStamper.SetEncryption(False, userPassword, ownerPassword, _
                                  PdfWriter.ALLOW_ASSEMBLY _
                                   Or PdfWriter.ALLOW_COPY _
                                   Or PdfWriter.ALLOW_DEGRADED_PRINTING _
                                   Or PdfWriter.ALLOW_FILL_IN _
                                   Or PdfWriter.ALLOW_MODIFY_ANNOTATIONS _
                                   Or PdfWriter.ALLOW_MODIFY_CONTENTS _
                                   Or PdfWriter.ALLOW_PRINTING _
                                   Or PdfWriter.ALLOW_SCREENREADERS _
                                )

    ' Entferne die Signaturinformationen aus dem original Pdf-Dokument
    pdfKopieStamper.FormFlattening = True
    pdfKopieStamper.Close()

    ' Schreibe den Inhalt der geflatteten Kopie in die Antwort
    retValue = pdfKopie.ToArray()

    ' Schließe die Bearbeitung des Dokumentes ab
    pdfKopie.Close()
    originalPdfReader.Close()

    Return retValue
End Function

Besides, we put all possible i text rights. As a result we get a PDF where page withdrawal (page-extraction) and document arrangement (document compilation) is not allowed?!

My questions are:

  1. is this a misbehavior of iText, Or, can one change this setting with iText in generally? If so, how (code example)?
  2. Can one the set these rights without any password too? Till present we have seen only functions for the setting rights always in conjunction with users and owners password.

Thanks for your help in advance!

Ingo

解决方案

The observations

The permission tab as seen by the OP indeed shows some missing permissions:

Inspecting the permissions of the OP's result file using Adobe Acrobat, though, there is a different result:

Merely flattening the OP's source file (not encrypting it at all!) one gets this file for which Adobe Acrobat even shows these permissions:

The explanation

This is a behavior of Adobe Reader, the PDF viewer most likely used by the OP: The permissions tab seen by the OP does not only represent what has or has not been forbidden during encryption but also restrictions of the PDF viewer itself.

There seems to be the misconception by the OP that using encryption and setting permission bits one can add to the capabilities compared to un-encrypted files. Actually it is the other way around: Encryption allows you to remove permissions compared to what is allowed for an un-encrypted document. By means of not using certain ALLOW_* permission bits you withdraw permissions. You get the maximum number of permissions by simply not encrypting the document.

In addition to the permissions of the un-encrypted document a specific PDF viewing program might require additional usage rights which are viewer-specific. Such PDF viewers (foremost Acrobat Reader) generally are fairly inexpensive or free but they do not offer the full functionality unless the document in question carries the appropriate usage rights.

Usage rights can be added by means of usage rights signatures. To apply such usage rights signatures you usually need software or services provided by the manufacturer of the PDF viewer in question.

To add usage rights for Adobe Reader, e.g., you can use Adobe Acrobat or certain Adobe Lifecycle services.

Thus,

The answers

As a result we get a PDF where page withdrawal (page-extraction) and document arrangement (document compilation) is not allowed

No. As can be seen above, your dest.pdf only disallows page extraction, and as soon as you stop encrypting, even that is allowed.

1 is this a misbehavior of iText, Or, can one change this setting with iText in generally? If so, how (code example)?

It is no misbehavior of iText, it is a behavior of Adobe Reader. Adobe Reader limits its features in general and only lifts the limitations for documents with usage rights. Such usage rights can only be applied by Adobe software.

2 Can one the set these rights without any password too? Till present we have seen only functions for the setting rights always in conjunction with users and owners password.

Using encryption actually is counter-productive as it can only be used to remove permissions, not to add them.

Resources

Additional information on the issue taken from the parallel post on the itext-questions mailing list:

  • a sample source file illustrating the issue src.pdf
  • the corresponding result file generated by the OP's code dest.pdf
  • a screen shot showing the OP's PDF viewer's permission tab for dest.pdf:

这篇关于问题设置权限(SetEncryption)在pdf内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆