How to programmatically convert Excel workbook to PDF with password protection in .NET

Copy link to clipboard
Copied
I'm able to convert an Excel workbook to PDF in code with Visual Studio. I would like to password protect the PDF file but can't find a property or method to accomplish this. Directly from Excel its possible to convert to PDF with protection but how is this possible in code?
' Create the Adobe component
myPDF = GetObject("", "PdfDistiller.PdfDistiller")
' Open Excel Workbook and save as post script
MyXL = New Excel.Application
MyXL.Workbooks.Open(InFile, 0)
MyXL.ActiveWorkbook.PrintOut(Copies:=1, Preview:=False, PrintToFile:=True, Collate:=True, PrToFileName:=PSFileName)
MyXL.Workbooks.Close()
' Convert the PS file to PDF
myPDF.FileToPDF(PSFileName, PDFFileName, "")
Thank you for any feedback to accomplish this.
Copy link to clipboard
Copied
You can specify security in Acrobat Distiller.

