我正在使用本教程http://www.4guysfromrolla.com/articles/030211-1.aspx,它使用 PDF 表单字段,让用户使用文本框输入字段。我想加密 pdf 并添加用户密码,以便在下载时需要密码才能打开 pdf。
public static byte[] GeneratePDF(string pdfPath, Dictionary<string, string> formFieldMap)
{
var output = new MemoryStream();
var reader = new PdfReader(pdfPath);
var stamper = new PdfStamper(reader, output);
var formFields = stamper.AcroFields;
foreach (var fieldName in formFieldMap.Keys)
formFields.SetField(fieldName, formFieldMap[fieldName]);
stamper.FormFlattening = true;
stamper.Close();
reader.Close();
byte[] content = output.ToArray();
// byte[] content = content;
// Write out PDF from memory stream.
return output.ToArray();
}