This is a migrated thread and some comments may be shown as answers.
exporting docx into pdf with password protection on pdf
1 Answer 29 Views
This is a migrated thread and some comments may be shown as answers.
Hagai
Top achievements
Rank 1
Hagai asked on 24 Jan 2019, 01:34 PM

Can someone tell me how can i export a docx document into pdf with password?

 

I tried the following but i get a corrupted pdf file:

 

RadFixedDocument documentFromPDFtmp = new RadFixedDocument();
                        Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider providerFromPDFtmp = new Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider();
                        var fileFormatProvider = new DocxFormatProvider();
                        RadFlowDocument documentFromWord = fileFormatProvider.Import(sourceFile.InputStream); ;
                        IFormatProvider<RadFlowDocument> formatProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider();                              
                        using (MemoryStream ms = new MemoryStream())
                        {                            
                            formatProvider.Export(documentFromWord, ms);                            
                            using (Stream stream = ms)
                            {
                                documentFromPDF = providerFromPDFtmp.Import(stream);
                            }
                            using (Stream output = new FileStream(path, FileMode.OpenOrCreate))
                            {
                                providerFromPDFtmp.ExportSettings.IsEncrypted = true;
                                providerFromPDFtmp.ExportSettings.UserPassword = Utils.GetConfigValue("PassPhrase");
                                providerFromPDFtmp.ExportSettings.ImageQuality = ImageQuality.Medium;
                                providerFromPDFtmp.Export(documentFromPDFtmp, output);
                            }
                        }

 

Looking forward for help with that

Thanks,

Hagai.

 

1 Answer, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 28 Jan 2019, 03:46 PM
Hello Hagai,

Thank you for your interest in Document Processing.

In order to export a DOCX file to PDF, you can use the WordsProcessing library. However, encryption is currently not supported functionality for WordsProcessing. We have logged a feature request in our feedback portal: DocxFormatProvider: Implement encryption of a document, where you can subscribe to be notified for any status updates. I added a vote on your behalf for the feature request to increase its priority. As a possible workaround, the exported PDF document can be encrypted using the format provider of the PdfProcessing library.

The generated PDF from the sample code you have provided is corrupted since the created RadFixedDocument instance contains no pages. In order to achieve the desired result, you need to encrypt the document exported with the WordsProcessing library. Please, find attached a sample project demonstrating this approach.

I hope this helps.

Regards,
Georgi
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.
Asked by
Hagai
Top achievements
Rank 1
Answers by
Georgi
Telerik team
Share this question
or