C# 使用iTextSharp自动打开受密码保护的pdf文件

C# 使用iTextSharp自动打开受密码保护的pdf文件,c#,pdf,itextsharp,C#,Pdf,Itextsharp,我的要求是,我想打开一个受密码保护的PDF,而不需要在浏览器中提示输入密码。我用C#实用地传递密码以直接打开PDF。我正在为此使用iTextSharp。它总是要求输入密码 请帮助我该怎么做。我的代码如下: iTextSharp.text.pdf.RandomAccessFileOrArray ra = new iTextSharp.text.pdf.RandomAccessFileOrArray(strPDFPath); if (ra != null) { System.IO.Memor

我的要求是,我想打开一个受密码保护的PDF,而不需要在浏览器中提示输入密码。我用C#实用地传递密码以直接打开PDF。我正在为此使用
iTextSharp
。它总是要求输入密码

请帮助我该怎么做。我的代码如下:

iTextSharp.text.pdf.RandomAccessFileOrArray ra = new iTextSharp.text.pdf.RandomAccessFileOrArray(strPDFPath);
if (ra != null)
{
    System.IO.MemoryStream ms = new System.IO.MemoryStream();
    //byte[] password = System.Text.ASCIIEncoding.ASCII.GetBytes(strPassword);
    iTextSharp.text.pdf.PdfReader thepdfReader = new iTextSharp.text.pdf.PdfReader(btSourceFile,btPassword);

    int pages = thepdfReader.NumberOfPages;
    iTextSharp.text.Document pdfDoc = new iTextSharp.text.Document();
    iTextSharp.text.pdf.PdfCopy pdfCopy = new iTextSharp.text.pdf.PdfCopy(pdfDoc, ms);

    pdfDoc.Open();
    int i = 0;
    while (i < pages)
    {
        pdfCopy.AddPage(pdfCopy.GetImportedPage(thepdfReader, i + 1));
        i += 1;
    }
    pdfDoc.Close();
}
iTextSharp.text.pdf.RandomAccessFileOrArray ra=new iTextSharp.text.pdf.RandomAccessFileOrArray(strpdPath);
如果(ra!=null)
{
System.IO.MemoryStream ms=新的System.IO.MemoryStream();
//byte[]password=System.Text.ASCIIEncoding.ASCII.GetBytes(strPassword);
iTextSharp.text.pdf.PdfReader thepdfReader=新的iTextSharp.text.pdf.PdfReader(btSourceFile,btPassword);
int pages=thepdfreeader.NumberOfPages;
iTextSharp.text.Document pdfDoc=新的iTextSharp.text.Document();
iTextSharp.text.pdf.PdfCopy PdfCopy=新iTextSharp.text.pdf.PdfCopy(pdfDoc,ms);
pdfDoc.Open();
int i=0;
while(i
可能重复[为使用未知随机所有者密码创建的PDF设置用户密码时出现问题]。答案很简单:如果定义了
用户
密码,那么就什么也做不了。如果定义了
所有者
密码,请使用
不道德阅读
(但要小心处理!)(),这样您就有了一个服务器端程序(网页)和一个受密码保护的PDF,对吗?您希望将此PDF传输到客户端(浏览器),但希望服务器“解锁”PDF,以便客户端不需要输入甚至不需要知道密码?这是正确的吗?我正在使用iTextSharp。它总是要求输入密码iTextSharp无法请求密码,因为它没有用户界面。所以请更清楚地解释你的问题。顺便说一句,在创建pdf之后,您似乎没有使用
MemoryStream ms
。这可能会导致您的问题吗?是的,Chris Haas这正是我的要求,请帮助我尝试什么方法。。。