exporting docx into pdf with password protection on pdf

2 posts, 0 answers
  1. Hagai
    Hagai avatar
    4 posts
    Member since:
    Jan 2012

    Posted 24 Jan Link to this post

    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.

     

  2. Georgi
    Admin
    Georgi avatar
    18 posts

    Posted 28 Jan Link to this post

    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 onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top