locked
Problem password encrypting PDF documents using document.saveas2 or document.exportasfixedformat RRS feed

  • Question

  • Hi folks,

      I have a problem trying to encrypt PDF documents using Word 2010+ with the document.saveas2 or document.exportasfixedformat methods. I tried saving using the document.saveas2 method first and setting the password property, this works fine when saving as a Word Doc file but when saving as PDF it fails to encrypt the file. I know that its possible to password protect PDF files using the save as dialog by setting options up to do so when choosing the PDF file format but... so far I've failed to find a way to do this in code and yes I've tried creating a macro to see if the code shows how to do this and it still didn't work! Hopefully someone out there has an answer for me!!! Also for the record I also failed to find any way of doing the same using exportasfixedformat.

    Thanks in advance,

    Keiron

    Friday, October 3, 2014 9:13 AM

Answers

  • Hi Keiron,

    Thanks for your feedback.

    According to my investigation, the saved PDF file will not have password if I use following code:

    Sub test()
        ActiveDocument.Password = "123"
        ActiveDocument.ExportAsFixedFormat OutputFileName:="D:\test.pdf", ExportFormat:=wdExportFormatPDF
    End Sub

    Then I tied set passowrd for this document and save it as a PDF file manually, I would get the following information:

    Thus I think this behavior is by design. Saving current protected document as PDF will lose the protection.

    I would suggest protecting the saved PDF file again after opening.

    Also, you could submit feedback:

    http://office.microsoft.com/en-US/suggestions.aspx

    Regards,

    George.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, October 6, 2014 5:17 AM