Using latest eval version of commercial PDFViewer, I change a field to readonly, set the security on a PDF, and saved it to disk.
<snip>
// we are looping through widget.FieldsWidget.List.Count
PdfField f = widget.FieldsWidget.List[i] as PdfField;
if (f.Name == "test")
{
PdfTextBoxFieldWidget tf = f as PdfTextBoxFieldWidget;
tf.Text = "X3G-T";
f.Flatten = true;
f.ReadOnly = true;
break;
}
<snip>
pdf.Security.OwnerPassword = ownerPassword;
pdf.Security.UserPassword = "spire#";
pdf.Security.Permissions = PdfPermissionsFlags.AccessibilityCopyContent | PdfPermissionsFlags.CopyContent | PdfPermissionsFlags.FillFields | PdfPermissionsFlags.FullQualityPrint | PdfPermissionsFlags.Print;
pdf.Security.KeySize = PdfEncryptionKeySize.Key256Bit;
using (FileStream fs = new FileStream(@"c:\encrypted3.PDF", FileMode.CreateNew))
{
pdf.SaveToStream(fs, FileFormat.PDF);
}
pdf.Close();
}
When I open this PDF in Acrobat, it behaves properly, asking for the user password, and with the correct permissions.
However, when I later attempt to open it in Spire, supplying the ownerPassword (the permissions password)
// pdf.Security.KeySize = PdfEncryptionKeySize.Key256Bit; // tried both ways, with/without this line
pdf.LoadFromFile(dialog.FileName, ownerPassword);
there is an exception in Spire.Pdf.dll :
Source array was not long enough. Check srcIndex and length, and the array's lower bounds.