VB.NET: Apply PDF Password & Permissions Programmatically — No Security Dialog

PDF-XChange Editor SDK for Developers

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Paul - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Anushka
User
Posts: 2
Joined: Thu Nov 27, 2025 7:33 am

VB.NET: Apply PDF Password & Permissions Programmatically — No Security Dialog

Post by Anushka »

Hello Team,

I am working in VB.NET to secure a PDF using PDF-XChange SDK.
I found a reference in your forum here: (link included):

viewtopic.php?p=162918&hilit=password#p162918

The example in that post uses:

Code: Select all

IPXC_SecurityPolicy secPolicy = secHandler.CreateNewPolicy(IPXV_Inst.GetDlgParentWindow(null));

This line automatically opens a password/security dialog window.
In my implementation, I do not want any UI prompts.
Instead, I need to:

✔ Set the user password
✔ Set the owner password
✔ Configure permissions (printing/copy/etc.)
✔ Apply security entirely in code, silently

May I please get an example of:

Creating IPXC_SecurityPolicy fully programmatically

Setting password values and permissions directly

What the IStream represents in this context (in-memory or file-backed data?)

A VB.NET code snippet following your recommended API approach

Below is the snippet from your forum that I am taking a reference from:

Code: Select all

secMethod = IPXS_Inst.StrToAtom("Standard");
IPXC_SecurityHandler secHandler = IPXC_Inst.GetSecurityHandler(secMethod);

// >> once do the following code
IStream streamWithSerializedSecPolicy; // create IStream-object to fill it below
...
IPXC_SecurityPolicy secPolicy = secHandler.CreateNewPolicy(IPXV_Inst.GetDlgParentWindow(null)); // it shows dlg to fill all sec-options
if (secPolicy != null)
     secPolicy.Store(streamWithSerializedSecPolicy);
// <<
...
IPXC_SecurityPolicy secPolicy = secHandler.LoadPolicy(streamWithSerializedSecPolicy);

op = IPXV_Inst.CreateOp(IPXV_Inst.Str2ID("op.document.setSecurity"));
op.Params["Input"].Add().v = doc;
op.Params["Options.Handler"] = "Standard";
op.Params["Options.Data"] = secPolicy;
op.Do();
I am unsure how to correctly construct the IStream object and load values into the policy without using the UI dialog, so guidance would be greatly appreciated.

Thank you!

Best Regards,
Anushka
User avatar
Daniel - PDF-XChange
Site Admin
Posts: 12219
Joined: Wed Jan 03, 2018 6:52 pm

Re: VB.NET: Apply PDF Password & Permissions Programmatically — No Security Dialog

Post by Daniel - PDF-XChange »

Hello, Anushka

I have raised this with the Dev team, requesting Vasyl's presence as well since he helped with the previous case. Once we have a reply from them, someone will come to post here with more details for you.

Kind regards,
Dan McIntyre - Support Technician
PDF-XChange Co. LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
Anushka
User
Posts: 2
Joined: Thu Nov 27, 2025 7:33 am

Re: VB.NET: Apply PDF Password & Permissions Programmatically — No Security Dialog

Post by Anushka »

Hello Support, Any Update?
User avatar
Sean - PDF-XChange
Site Admin
Posts: 629
Joined: Wed Sep 14, 2016 5:42 pm

Re: VB.NET: Apply PDF Password & Permissions Programmatically — No Security Dialog

Post by Sean - PDF-XChange »

Hi Anushka,

There is no update on this yet - it will be posted here in due course.

Kind regards,
Sean Godley
Technical Writer
PDF-XChange Co LTD
Sales: +1 (250) 324-1621
Fax: +1 (250) 324-1623
User avatar
Vasyl - PDF-XChange
Site Admin
Posts: 2468
Joined: Thu Jun 30, 2005 4:11 pm

Re: VB.NET: Apply PDF Password & Permissions Programmatically — No Security Dialog

Post by Vasyl - PDF-XChange »

Hi Anushka,

I'm afraid there's currently no way to specify a password programmatically and without the UI. I think we'll add that feature later.

RT#7696: FR: Operation op.document.setSecurity: develop alternative and 3rd-dev-friendly method to set security-params

Cheers.
PDF-XChange Co. LTD (Project Developer)

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.