This is a migrated thread and some comments may be shown as answers.

Encrypt an existing PDF file

11 Answers 819 Views
PdfProcessing
This is a migrated thread and some comments may be shown as answers.
Salman Syed
Top achievements
Rank 1
Salman Syed asked on 14 Feb 2016, 08:34 PM
How can i encypt an existing PDF file? I just want to set the password on it.

11 Answers, 1 is accepted

Sort by
0
Tanya
Telerik team
answered on 17 Feb 2016, 04:34 PM
Hi,

I replied to the support thread on the same topic, but will post my answer here as well in case anyone else have the same question:

"You could protect a document through the ExportSettings of PdfFormatProvider. More details on how this could be achieved are available in our online documentation."

Regards,
Tanya
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Cheryl
Top achievements
Rank 1
Iron
answered on 12 Sep 2016, 12:02 AM

Hello, is there a way to set an Owner Password to an existing PDF, so that the PDF can be viewed without a password but not edited?

We're using Telerik Reporting to generate a report and save as a PDF.  We need to be able to lock down editing and as Telerik Reporting doesn't appear to allow for this, we are wondering whether we can import the already created PDF using PDFProcessing so that we can apply a password to it.

We don't want to use a third party component if we can help it.

Any help greatly appreciated.

Cheryl

 

0
Tanya
Telerik team
answered on 14 Sep 2016, 01:46 PM
Hello Cheryl,

The settings of PdfFormatProvider allow you to protect the document with a password or to encrypt it. I added a feature request for the functionality you need to our feedback portal where you can vote and track the progress of the task.

Regards,
Tanya
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Muhammad
Top achievements
Rank 1
answered on 19 Jul 2018, 01:46 PM

HI Admin,

we are exporting PDF by using below code with Telerik control version 2014.1.331.40. we are unable to find the password property (settings.UserPassword = "D0cum3ntP4ssw0rd") in PdfExportSettings  class object as shown below. Please guide us regarding the prerequisite of using PdfExportSettings password functionality. Is there any other version of controls or any DLL is required

<div style=" background-color: #fff;"><span style=" "><span style=" margin-left: 0px !important;"><code style="color: #000;"><</code><code style="color: #069;font-weight: bold;">p</code><code style="color: #000;">>PdfExportSettings settings = new PdfExportSettings();</code></span></span></div><div style=" background-color: #F8F8F8;"><span style=" "><span style=" margin-left: 0px !important;"><code style="color: #000;"></</code><code style="color: #069;font-weight: bold;">p</code><code style="color: #000;">><</code><code style="color: #069;font-weight: bold;">p</code><code style="color: #000;">></</code><code style="color: #069;font-weight: bold;">p</code><code style="color: #000;">><</code><code style="color: #069;font-weight: bold;">p</code><code style="color: #000;">>private void ExportIntoStream()<</code><code style="color: #069;font-weight: bold;">br</code><code style="color: #000;">>        {<</code><code style="color: #069;font-weight: bold;">br</code><code style="color: #000;">>            try<</code><code style="color: #069;font-weight: bold;">br</code><code style="color: #000;">>            {<</code><code style="color: #069;font-weight: bold;">br</code><code style="color: #000;">>                RadDocument radDocument = (new XamlFormatProvider()).Import(this.DocumentXaml);<</code><code style="color: #069;font-weight: bold;">br</code><code style="color: #000;">>                (new PdfFormatProvider()).Export(radDocument, this.output);<</code><code style="color: #069;font-weight: bold;">br</code><code style="color: #000;">>            }<</code><code style="color: #069;font-weight: bold;">br</code><code style="color: #000;">>            catch (Exception exception)<</code><code style="color: #069;font-weight: bold;">br</code><code style="color: #000;">>            {<</code><code style="color: #069;font-weight: bold;">br</code><code style="color: #000;">>                throw exception;<</code><code style="color: #069;font-weight: bold;">br</code><code style="color: #000;">>            }<</code><code style="color: #069;font-weight: bold;">br</code><code style="color: #000;">>        }</</code><code style="color: #069;font-weight: bold;">p</code><code style="color: #000;">></code></span></span></div>
0
Muhammad
Top achievements
Rank 1
answered on 19 Jul 2018, 02:01 PM

HI Admin,
we are exporting PDF by using below code with Telerik control version 2014.1.331.40. we are unable to find the password property (settings.UserPassword = "D0cum3ntP4ssw0rd") in PdfExportSettings  class object as shown below. Please guide us regarding the prerequisite of using PdfExportSettings password functionality. Is there any other version of controls or any DLL is required

PdfExportSettings settings = new PdfExportSettings();
private void ExportIntoStream()
 {
try
  
RadDocument radDocument = (new XamlFormatProvider()).Import(this.DocumentXaml);
  
(new PdfFormatProvider()).Export(radDocument, this.output);
 
catch (Exception exception)
 throw exception;}}
0
Tanya
Telerik team
answered on 24 Jul 2018, 08:26 AM
Hello Muhammad,

From the snippet you shared, it seems like you are using the API of RadRichTextBox. If so, the control currently doesn't support protecting PDF documents with a password and we have logged a feature request to add this functionality on our public portal. You can vote for the implementation as well as track the status of the task using this feedback item.

The PdfExportSettings class is part of the PdfProcessing library, from the Telerik Document Processing package. You could use it to import the generated from RadRichTextBox PDF document and apply it a password. Please, note that this library is released with Q2 2014 and you will need to get a newer version of the controls to use it.

Hope this helps.

Regards,
Tanya
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which you to write beautiful native mobile apps using a single shared C# codebase.
0
Hagai
Top achievements
Rank 1
Veteran
answered on 07 Mar 2019, 07:14 AM

how can i decrypt an existing pdf file and send it to the user?

if (File.Exists(filePath))
                {
                    RadFixedDocument documentFromPDF = new RadFixedDocument();
                    Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider providerFromPDF = new Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider();
                    PdfImportSettings settings = new PdfImportSettings();
                    settings.UserPasswordNeeded += (s, a) =>
                    {
                        a.Password = Utils.GetConfigValue("PassPhrase");
                    };
                    providerFromPDF.ImportSettings = settings;
                    using (Stream stream = File.OpenRead(filePath))
                    {
                        documentFromPDF = providerFromPDF.Import(stream);
                    }
                    byte[] renderedBytes = null;
                    using (MemoryStream output = new MemoryStream())
                    {
                        providerFromPDF.ExportSettings.ImageQuality = ImageQuality.Medium;
                        providerFromPDF.Export(documentFromPDF, output);
                        renderedBytes = output.ToArray();
                    }
                    HttpContext.Current.Response.AddHeader("content-disposition", string.Format("attachment;filename={0}", fileName));
                    Response.ContentType = "application/pdf";
                    HttpContext.Current.Response.BinaryWrite(renderedBytes);
                }

 

i tried this code but i recive an error:

System.InvalidCastException: Unable to cast object of type 'Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Types.PdfLiteralString' to type 'Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Elements.Destinations.DestinationObject'. at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Data.PdfPropertyBase`1.PrepareValue(PostScriptReader reader, IPdfImportContext context, PdfPrimitive value) at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Data.DirectProperty`1.SetValue(PostScriptReader reader, IPdfImportContext context, PdfPrimitive value) at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Elements.Common.PdfObject.LoadFromDictionary(PostScriptReader reader, IPdfImportContext context, PdfDictionary dictionary) at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Converters.Converter.ConvertFromDictionary(Type type, PostScriptReader reader, IPdfImportContext context, PdfDictionary dictionary) at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Converters.Converter.Convert(Type type, PostScriptReader reader, IPdfImportContext context, PdfPrimitive value) at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Converters.Converter.Convert(Type type, PostScriptReader reader, IPdfImportContext context, PdfPrimitive value) at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Data.PdfPropertyBase`1.PrepareValue(PostScriptReader reader, IPdfImportContext context, PdfPrimitive value) at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Data.DirectProperty`1.SetValue(PostScriptReader reader, IPdfImportContext context, PdfPrimitive value) at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Elements.Common.PdfObject.LoadFromDictionary(PostScriptReader reader, IPdfImportContext context, PdfDictionary dictionary) at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Converters.Converter.ConvertFromDictionary(Type type, PostScriptReader reader, IPdfImportContext context, PdfDictionary dictionary) at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Converters.Converter.Convert(Type type, PostScriptReader reader, IPdfImportContext context, PdfPrimitive value) at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Converters.Converter.Convert(Type type, PostScriptReader reader, IPdfImportContext context, PdfPrimitive value) at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Types.PdfCollectionBase`1.ConvertElementToType[T](PostScriptReader reader, IPdfImportContext context, PdfPrimitive element) at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Elements.DocumentStructure.Page.CopyPropertiesTo(PostScriptReader reader, IRadFixedDocumentImportContext context, RadFixedPage fixedPage) at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Elements.DocumentStructure.DocumentCatalog.CopyPagePropertiesTo(PostScriptReader reader, IRadFixedDocumentImportContext context) at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider.ImportOverride(Stream input) at ...

 

0
Hagai
Top achievements
Rank 1
Veteran
answered on 07 Mar 2019, 11:05 AM

Also, can you tell me what is the difference between the following two pdf files? the first one I'm able to read and download to the user and the second one gives me the above error.

https://hagaih.com/wp-content/uploads/2019/03/SampleA.pdf

https://hagaih.com/wp-content/uploads/2019/03/SampleB.pdf

0
Tanya
Telerik team
answered on 11 Mar 2019, 03:20 PM
Hello Hagai,

It seems like there is an unsupported feature or issue which is encountered during the import of the document. To verify what is causing the error, we would need to test an example document. I checked the two documents from the links but they are password protected and I cannot access them. Would it be convenient for you to share the passwords? Another option is to share the documents and passwords privately through our support channel, so you don't share them in the public forum.

Regards,
Tanya
Progress Telerik
Get quickly and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Hagai
Top achievements
Rank 1
Veteran
answered on 12 Mar 2019, 04:00 AM
can you send me your email so I'll be able to send you the password?
0
Tanya
Telerik team
answered on 14 Mar 2019, 01:37 PM
Hello Hagai,

If you would like to share the passwords in a private channel, you can use the support system. For your convenience, I created a new support ticket on your behalf. Please, find it in your telerik.com profile and reply there with more information. The ID of the new thread is 1400502.

Regards,
Tanya
Progress Telerik
Get quickly and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
PdfProcessing
Asked by
Salman Syed
Top achievements
Rank 1
Answers by
Tanya
Telerik team
Cheryl
Top achievements
Rank 1
Iron
Muhammad
Top achievements
Rank 1
Hagai
Top achievements
Rank 1
Veteran
Share this question
or