11 Answers, 1 is accepted
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
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
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
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>
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;}}
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
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 ...
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
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
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