在升级iText7时,我认为需要一个EncryptionConstants.ENCRYPTION_AES_128是正确的。我也不知道如何将writerProperties添加到我的PdfDocument中
旧版本
pdfDocument.Writer.SetEncryption(true, null, null, PdfWriter.ALLOW_COPY | PdfWriter.ALLOW_PRINTING);新版本
WriterProperties writerProperties = new WriterProperties();
writerProperties.SetStandardEncryption(null, null, EncryptionConstants.ALLOW_PRINTING | EncryptionConstants.ALLOW_COPY, EncryptionConstants.ENCRYPTION_AES_128);发布于 2022-03-15 16:04:02
请检查以下代码的iText 7添加或加密与所有者和用户的密码pdf文件。
public class EncryptPdf
{
public static readonly String DEST = "results/sandbox/security/encrypt_pdf.pdf";
public static readonly String SRC = "../../../resources/pdfs/hello.pdf";
public static readonly String OWNER_PASSWORD = "World";
public static readonly String USER_PASSWORD = "Hello";
public static void Main(String[] args)
{
FileInfo file = new FileInfo(DEST);
file.Directory.Create();
new EncryptPdf().ManipulatePdf(DEST);
}
protected void ManipulatePdf(String dest)
{
PdfDocument document = new PdfDocument(new PdfReader(SRC), new PdfWriter(dest,
new WriterProperties().SetStandardEncryption(
Encoding.UTF8.GetBytes(USER_PASSWORD),
Encoding.UTF8.GetBytes(OWNER_PASSWORD),
EncryptionConstants.ALLOW_PRINTING,
EncryptionConstants.ENCRYPTION_AES_128 | EncryptionConstants.DO_NOT_ENCRYPT_METADATA
)));
document.Close();
}
}https://stackoverflow.com/questions/71484814
复制相似问题