ByteScout PDF SDK - C# - Remove Password and Protection From PDF - ByteScout

ByteScout PDF SDK – C# – Remove Password and Protection From PDF

  • Home
  • /
  • Articles
  • /
  • ByteScout PDF SDK – C# – Remove Password and Protection From PDF

How to remove password and protection from PDF in C# and ByteScout PDF SDK

This code in C# shows how to remove password and protection from PDF with this how to tutorial

Remove password and protection from PDF is easy to implement in C# if you use these source codes below. ByteScout PDF SDK is the component to help programmers in generating new pdf files, modifying and updating existing pdf documents or pdf forms. Provides support for auto-filling pdf forms, adding text with adjustable font, style, size, font family, new form fields, vector and raster drawings and you can use it to remove password and protection from PDF with C#.

You will save a lot of time on writing and testing code as you may just take the C# code from ByteScout PDF SDK for remove password and protection from PDF below and use it in your application. Just copy and paste the code into your C# application’s code and follow the instruction. This basic programming language sample code for C# will do the whole work for you to remove password and protection from PDF.

Free trial version of ByteScout PDF SDK is available for download from our website. Get it to try other source code samples for C#.

Try it today: Get 60 Day Free Trial or sign up for Web API

Program.cs
      
using Bytescout.PDF; using System; namespace RemovePdfProtection { class Program { static void Main(string[] args) { try { //Files string fileName = "ProtectedPDFFile.pdf"; string fileName_UnProtected = "UnProtectedPDFFile.pdf"; //Protected file password string filePassword = "admin@123"; //Process file to remove password using (Document document = new Document()) { document.RegistrationName = "demo"; document.RegistrationKey = "demo"; document.Load(fileName, filePassword); // Remove password protection and encryption document.Security.OwnerPassword = String.Empty; document.Security.UserPassword = String.Empty; document.Security.EncryptionAlgorithm = EncryptionAlgorithm.None; // Remove restrictions document.Security.AllowAccessibilitySupport = true; document.Security.AllowAssemlyDocument = true; document.Security.AllowContentExtraction = true; document.Security.AllowFillForms = true; document.Security.AllowModifyAnnotations = true; document.Security.AllowModifyDocument = true; document.Security.AllowPrintDocument = true; document.Security.PrintQuality = PrintQuality.HightResolution; //Save Unprotected file document.Save(fileName_UnProtected); } Console.WriteLine("PDF restrictions removed successfully!"); } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.WriteLine(); Console.WriteLine("Press any key to exit...."); Console.ReadLine(); } } }

Try it today: Get 60 Day Free Trial or sign up for Web API

RemovePdfProtection.NETCore.csproj
      
<?xml version="1.0" encoding="utf-8"?> <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp2.0</TargetFramework> <EnableDefaultCompileItems>false</EnableDefaultCompileItems> <GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> <GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> <GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute> <GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute> <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> <GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute> <GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute> <GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute> <GenerateAssemblyTrademarkAttribute>false</GenerateAssemblyTrademarkAttribute> <GenerateAssemblyCultureAttribute>false</GenerateAssemblyCultureAttribute> <GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute> </PropertyGroup> <ItemGroup> <Compile Include="Program.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <None Include="ProtectedPDFFile.pdf"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </None> </ItemGroup> <ItemGroup> <PackageReference Include="Microsoft.Windows.Compatibility" Version="2.0.0" /> </ItemGroup> <ItemGroup> <Reference Include="Bytescout.PDF"> <SpecificVersion>False</SpecificVersion> <HintPath>c:\Program Files\Bytescout PDF SDK\netcoreapp2.0\Bytescout.PDF.dll</HintPath> </Reference> </ItemGroup> </Project>

Try it today: Get 60 Day Free Trial or sign up for Web API

RemovePdfProtection.csproj
      
<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <ProjectGuid>{8B33CB1C-B6A2-4750-9D1C-EB963DC8A17D}</ProjectGuid> <OutputType>Exe</OutputType> <RootNamespace>RemovePdfProtection</RootNamespace> <AssemblyName>RemovePdfProtection</AssemblyName> <TargetFrameworkVersion>v2.0</TargetFrameworkVersion> <FileAlignment>512</FileAlignment> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PlatformTarget>AnyCPU</PlatformTarget> <DebugSymbols>true</DebugSymbols> <DebugType>full</DebugType> <Optimize>false</Optimize> <OutputPath>bin\Debug\</OutputPath> <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PlatformTarget>AnyCPU</PlatformTarget> <DebugType>pdbonly</DebugType> <Optimize>true</Optimize> <OutputPath>bin\Release\</OutputPath> <DefineConstants>TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> <Reference Include="Bytescout.PDF, Version=1.8.2.254, Culture=neutral, PublicKeyToken=f7dd1bd9d40a50eb, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> <HintPath>c:\Program Files\Bytescout PDF SDK\net2.0\Bytescout.PDF.dll</HintPath> </Reference> <Reference Include="System" /> <Reference Include="System.Data" /> <Reference Include="System.Xml" /> </ItemGroup> <ItemGroup> <Compile Include="Program.cs" /> </ItemGroup> <ItemGroup> <None Include="ProtectedPDFFile.pdf"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </None> </ItemGroup> <ItemGroup> <Folder Include="Properties\" /> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> </Project>

Try it today: Get 60 Day Free Trial or sign up for Web API

MORE INFORMATION

Get 60 Day Free Trial or Visit ByteScout PDF SDK page

Explore ByteScout PDF SDK documentation

WEB API VERSION

Sign Up for free Web API key

Explore Web API Documentation

Tutorials:

prev
next