HTML JPG PDF XML DOCX
  Product Family
PDF

Password change in PDF via .NET SDK

API for password changing in PDF documents using Aspose.PDF Cloud .NET SDK

Get Started

How to change a password in PDF via Cloud .NET SDK

For passoed change in PDF documents, we’ll use Aspose.PDF Cloud .NET SDK This Cloud SDK assists .NET programmers in developing cloud-based PDF creator, annotator, editor, and converter apps using C#, ASP.NET, or other .NET languages for various cloud platforms.Open NuGet package manager, search for Aspose.PDF Cloud and install. You may also use the following command from the Package Manager Console.

Package Manager Console Command


     
    PM> Install-Package Aspose.Pdf-Cloud
     

Steps to password change in PDF via .NET

Aspose.PDF Cloud developers can easily load & change a password in PDF just in a few lines of code.

  1. Create a new Configuration object with your Application Secret and Key
  2. Create an object to connect to the Cloud API
  3. Upload your encrypted document file
  4. Call API to Password Change in Pdf document.
  5. Checks the response and logs the result.
  6. Downloads the updated file for local use.
 

Password change in PDF using Cloud .NET SDK


    using Aspose.Pdf.Cloud.Sdk.Api;
    using Aspose.Pdf.Cloud.Sdk.Model;

    namespace EncryptDecrypt
    {
        public class PdfPasswordChange
        {
            private string ToBase64(string str)
            { // Convert string to Base64. 
                var bytes = Encoding.UTF8.GetBytes(str);
                return Convert.ToBase64String(bytes);
            }

            public static async Task Modiry(string documentName, string outputName, staring localFolder, string remoteFolder)
            {
                // Get your AppSid and AppSecret from https://dashboard.aspose.cloud (free registration required). 
		pdfApi = new PdfApi(AppSecret, AppSid);

                using (var file = File.OpenRead(Path.Combine(localFolder, documentName)))
		{ // Upload the local encrypted PDF to cloud storage folder name.
                    FilesUploadResult uploadResponse = await pdfApi.UploadFileAsync(Path.Combine(remoteFolder, documentName), documentName);
                    Console.WriteLine(uploadResponse.Uploaded[0]);
                }

                string ownerPassword = "Owner-Password";

                string newOwnerPassword = "NEW-Owner-Password";
                string newUserPassword = "NEW-User-Password";

                // Password change in PDF on cloud storage.
                AsposeResponse response = await pdfApi.PostChangePasswordDocumentInStorageAsync(
                    documentName,
                    helper.ToBase64(ownerPassword),
                    helper.ToBase64(newUserPassword),
                    helper.ToBase64(newOwnerPassword),
                    folder: remoteFolder);

                // Checks the response and logs the result.
                if (response == null)
                    Console.WriteLine("PdfPasswordChange(): Unexpected error!");
                else if (response.Code < 200 || response.Code > 299)
                    Console.WriteLine("PdfPasswordChange(): Failed to change a password in document.");
                else
                {  // Downloads the updated file for local use.
                    Console.WriteLine("PdfPasswordChange(): password in document '{0} successfully changed.", documentName);
                    Stream stream = pdfApi.DownloadFile(Path.Combine(remoteFolder, documentName));
                    using var fileStream = File.Create(Path.Combine(localFolder, "password_change_" + outputName));
                    stream.Position = 0;
                    await stream.CopyToAsync(fileStream);
                    Console.WriteLine("PdfPasswordChange(): File '{0}' successfully downloaded.", "password_change_" + outputName);
               }
            }
        }
    }
 

Password change in PDF via .NET SDK

Change a password in a PDF document is crucial when access to its contents is restricted due to encryption. It allows authorized users to regain full control over the file, enabling editing, viewing, and content extraction. This process is especially important in workflows where secure documents must be accessed programmatically or integrated into larger systems.

Using tools like Aspose.PDF Cloud, password changing can be performed easily and securely with just the correct owner or user password. This ensures sensitive information remains protected while still allowing flexibility for those who need legitimate access.

Ultimately, password changing in a PDF enables smooth document handling and reinforces the importance of strong yet manageable document security practices. Change a password in PDF documents with Aspose.PDF Cloud .NET SDK.

With our .NET library you can:

  • Add PDF document’s header & footer in text or image format.
  • Add tables & text or image stamps to PDF documents.
  • Append multiple PDF documents to an existing file.
  • Work with PDF attachments, annotations, & form fields.
  • Apply encryption or decryption to PDF documents & set a password.
  • Delete all stamps & tables from a page or entire PDF document.
  • Delete a specific stamp or table from the PDF document by its ID.
  • Replace single or multiple instances of text on a PDF page or from the entire document.
  • Extensive support for converting PDF documents to various other file formats.
  • Extract various elements of PDF files & make PDF documents optimized.
  • You can try out our free Apps to test the functionality online.

  •