我加密了pdf并希望将其保存到数据库中,下面是关于我是如何做到的代码。我想知道是否有任何方法可以设置Created" PDFEncrypted.pdf"在不使用FileUploader的情况下进入Stream fs?
string WorkingFolder = Server.MapPath("~/Files/");
string InputFile = Path.Combine(WorkingFolder, "PDF.pdf");
string OutputFile = Path.Combine(WorkingFolder, "PDFEncrypted.pdf");
using (Stream input = new FileStream(InputFile, FileMode.Open, FileAccess.Read, FileShare.Read))
{
using (Stream output = new FileStream(OutputFile, FileMode.Create, FileAccess.Write, FileShare.None))
{
PdfReader reader = new PdfReader(InputFile);
PdfEncryptor.Encrypt(reader, output, true, "pass123", "secret", PdfWriter.ALLOW_SCREENREADERS);
}
}
所以我有这些代码上传
Stream fs = FileUpload1.PostedFile.InputStream;
BinaryReader br = new BinaryReader(fs);
Byte[] bytes = br.ReadBytes((Int32)fs.Length);