The example’s encrypted.pdf passed veraPDF’s PDF/UA-1 profile: run verapdf -f ua1 --format text encrypted.pdf after saving it. The code needs a tagged PDF named accessible.pdf: use the one in the zip or substitute your own tagged PDF.
dotnet add package RecursiveAI.OnePdfRequires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
using OnePdf; var edit = new PdfOpenOptions { AllowEditing = true }; using var doc = PdfDocument.Open("accessible.pdf", edit); var encryption = new PdfEncryptionOptions { Cipher = PdfCipher.Aes256, UserPassword = "", OwnerPassword = "demo-owner", Permissions = PdfPermissions.ExtractForAccessibility }; doc.Save("encrypted.pdf", new PdfSaveOptions { PdfUA = new() { Part = PdfUAPart.Part1 }, Encryption = PdfEncryptionAction.Set, NewEncryption = encryption }); Console.WriteLine("Wrote encrypted.pdf");
Paste the code above into Program.cs of a new dotnet new console project and dotnet run, or unzip the example and dotnet run.
Wrote encrypted.pdfThe empty user password lets readers open the file without a prompt; the owner password controls full access. Use your own owner password outside the demo. If OnePDF finds violations it can’t repair, the PDF/UA save throws PdfUAException. As the PDF/UA guide puts it, “a clean check is not proof of conformance.”
Variations
Use AES-128 when a recipient requires it. Replace the Cipher assignment and leave the accessibility permission in place:
Cipher = PdfCipher.Aes128,Related recipes
The short answer
Open a tagged PDF with editing enabled. Set PdfUA.Part to Part1, Encryption to Set, and NewEncryption.Cipher to Aes256. Include PdfPermissions.ExtractForAccessibility so the encryption settings don’t block extraction for assistive technology. The sample’s pass does not guarantee that another PDF will pass.
Can a PDF/UA-1 file be encrypted?
Yes. PDF/UA-1 allows encryption provided the accessibility extraction permission stays enabled. That permission is separate from ordinary text copying; the example requests accessibility extraction without granting all permissions. It is also separate from the password needed to open a file. Here that password is empty, so the file is encrypted but isn’t a way to keep the contents confidential from someone who obtains a copy. PDF/A is an archival standard with different rules: a PDF/A file can’t be encrypted.
Why does an AES-256 PDF/UA-1 file use PDF 1.7?
PDF/UA-1 requires a PDF 1.x header. OnePDF 1.26.1 writes PDF 1.7 with the Adobe AES-256 extension declaration in the catalog. That declaration lets a PDF 1.7 reader that supports the extension identify revision 6 encryption. OnePDF versions 1.0.0 through 1.25.2 could write a PDF 2.0 header for this combination; save files made with that combination again. Saving as PDF/UA-2 instead keeps PDF 2.0, but that doesn’t meet a requirement to deliver part 1.
How do you check if an encrypted PDF is accessible?
Start with a tagged source whose headings, reading order, language, and any alternative text are correct. The save can make some structural repairs, but it won’t decide what an image means or invent missing tags. Check the final file, not just the unencrypted input: an automated PDF/UA check covers machine-testable rules, while a human review is still needed for the meaning and order of the content. If you set an opening password, the person reviewing the PDF also needs that password.