在C#中需要iText7 HTML到PDF加密代码 [英] Need iText7 HTML to PDF Encryption Code in C#

查看:276
本文介绍了在C#中需要iText7 HTML到PDF加密代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了iText7 Trail版本软件包以将html文件转换为pdf。我已经使用提到的正确代码成功地将html转换为pdf(iText Software)。但是仍然不清楚如何为创建的pdf设置密码。将html文件转换为pdf后,应使用密码保护pdf文件。因此,请任何人帮助我,从html转换时,c#中用于加密pdf文件的代码是什么。

I Have Installed iText7 trail Version Packages to convert html file into pdf. I have succefully converted html to pdf using proper code like they(iText Software) mentioned.But still i am not clear to set the Password for created pdf. After converting html file to pdf,the pdf file should be protected with password.so please anyone help me what is the code in c# to encrypt the pdf file while converting from html.

推荐答案

您没有共享任何代码(当您在Stack Overflow上发布问题时,这实际上是必要条件),但是我假设您正在创建 PdfWriter 。如果不是,请检查不同的变体以从HTML创建PDF。在内部,PDF编写过程由 PdfWriter 实例完成,因此,如果您没有 PdfWriter 实例,您的代码,则必须使用更深入地了解底层功能的方法。

You didn't share any code (which is actually a requirement when you post a question on Stack Overflow), but I assume that you are creating a PdfWriter somewhere in the process. If not, check out the different variations to create a PDF from HTML. Internally, the PDF writing process is done by a PdfWriter instance, so if you don't have a PdfWriter instance in your code, you'll have to use a method that reaches somewhat deeper into the lower-level functionality.

创建 PdfWriter code>实例,您可以定义 WriterProperties 。这在 Building Blocks教程的第7章。您必须创建一个 PdfWriter 实例,该实例可以接受目标位置(要创建的PDF的路径),还可以接受 WriterProperties 实例:

When you create the PdfWriter instance, you can define WriterProperties. This is explained in Chapter 7 of the Building Blocks tutorial. You have to create a PdfWriter instance that accepts a destination (the path to the PDF that you are creating), but also a WriterProperties instance:

byte[] user = "abc".getBytes();
byte[] owner = "xyz".getBytes();
PdfDocument pdf = new PdfDocument(new PdfWriter(dest,
    new WriterProperties().setStandardEncryption(user, owner,
        EncryptionConstants.ALLOW_PRINTING | EncryptionConstants.ALLOW_ASSEMBLY,
        EncryptionConstants.ENCRYPTION_AES_256)));

在这种情况下,我们使用AES 256加密(ISO- 32000-2)使用用户和所有者密码。我们允许打印和组装文档。

In this case, we use AES 256 encryption (the only encryption algorithm that will be allowed in ISO-32000-2) using a user and an owner password. We allow printing and assembly of the document.

这篇关于在C#中需要iText7 HTML到PDF加密代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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