Add a Password to a PDF with .NET Core / C#

July 14th, 2021 / by api2pdf /


API2PDF is a REST API that provides utilities for manipulating PDFs and other files. You landed here because you just want a simple and reliable way to add passwords to PDF files as a c# / .net core developer.

Our API will take your .pdf file and return back to you a new .pdf file with the bookmarks added. Just make sure your PDF is saved as a .pdf file and accessible at a URL that our service can ingest. For example, see this: — Ideally a file storage provider like S3 or Azure Blob Storage. See the code sample below.

Add Passwords to PDFs with C# / .NET Core

Step 1) Open up your package manager and run the command

Install-Package Api2Pdf -Version 2.0.0

Step 2) Grab an API key from Only takes 60 seconds.

Step 3) Use the sample code below and replace “YOUR-API-KEY” with the api key you acquired in step 2.

var a2pClient = new Api2Pdf("YOUR-API-KEY");

var request = new PdfBookmarkRequest
    Url = "http://link-to-your-pdf",
    UserPassword = "yourpassword"
var apiResponse = a2pClient.PdfSharp.SetPassword(request);

And that’s it! Modify the code as you see fit. Hopefully this saves you time and makes adding passwords to PDF files easy and painless for those writing C# / .NET core code.

See full github library

We have a whole .net based client library for our API that does a lot more than just this. Check out the full library capabilities here:

Tags: , , ,

Comments are closed.