MS Office Interop - DOCX to PDF with a password

Viewed 318

I have MS office 2016 and I want to convert DOCX to PDF with password using Microsoft.Office.Interop.Word.

I saw a lot of code samples right here, but no one shows parameters for PDF.

The code:

// Cast as Object for word Open method
    Object filename = (Object)wordFile.FullName;

    // Use the dummy value as a placeholder for optional arguments
    Document doc = word.Documents.Open(ref filename, ref oMissing,
        ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
        ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
        ref oMissing, ref oMissing, ref oMissing, ref oMissing);
    doc.Activate();

    object outputFileName = wordFile.FullName.Replace(".docx", ".pdf");
    object fileFormat = WdSaveFormat.wdFormatPDF;

    // Save document into PDF Format
    doc.SaveAs(ref outputFileName,
        ref fileFormat, ref oMissing, ref oMissing,
        ref oMissing, ref oMissing, ref oMissing, ref oMissing,
        ref oMissing, ref oMissing, ref oMissing, ref oMissing,
        ref oMissing, ref oMissing, ref oMissing, ref oMissing);

I may save DOCX to PDF. It works.

But I want to use this option: SaveAs -> PDF -> Options -> Encrypt the document with a password.

Please tell me how to do that? Any manual or references. Thanks [ [

2 Answers

The Microsoft Word API does not support the password-protection of documents saved in any format other than as a Word document.

Related