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.
Dim sFile As String = "C:\sample.pdf"
Dim pAuthCallback As LIBNAME.IPXC_DocAuthCallback = Nothing
Try
pdfInst.OpenDocumentFromFile(sFile, pAuthCallback)
Catch ex As Exception
Dim hr As Integer = Marshal.GetHRForException(ex)
ShowErrMsg(hr)
End Try
We don't use vb.net as our primary writing language but we'll try to translate it.
You need pAuthCallback for the documents with passwords - it's not needed by default.
class CDocAuthCallback : LIBNAME.IPXC_DocAuthCallback
{
public LIBNAME.IPXS_Inst m_pxsInst = null;
public void AuthDoc(LIBNAME.IPXC_Document pDoc, uint nFlags)
{
if ((pDoc == null) || (m_pxsInst == null))
{
return;//throw new COMException("", VSConstants.E_INVALIDARG);
}
//Checking whether the document has any security
UInt32 nNameAtom = pDoc.GetSecurityHandlerType(false);
if (nNameAtom == 0)
{
//No security so successfully opened doc
//...
return;//throw new COMException("", VSConstants.S_OK);
}
//Else we must provide a password
UInt32 nStandard = m_pxsInst.StrToAtom("Standard");
LIBNAME.PXC_PermStatus status = LIBNAME.PXC_PermStatus.Perm_ReqGranted;
//Comparing whether the security handler type is Standard
if (nStandard != nNameAtom)
{
//We do not support this one
return;//throw new COMException("", VSConstants.E_INVALIDARG);
}
status = pDoc.AuthorizeWithPassword("YourPasswordHere");
if (status != LIBNAME.PXC_PermStatus.Perm_ReqGranted)
{
//We don't have permission to open doc
return;//throw new COMException("", VSConstants.E_NOTIMPL);
}
}
}
private void OpenDocumentFromFileSample(string sFilePath, LIBNAME.IPXC_Inst pInst)
{
//Getting IPXS_Inst if you don't have it
LIBNAME.IPXS_Inst pSInt = (LIBNAME.IPXS_Inst)pInst.GetExtension("PXS");
CDocAuthCallback clbk = new CDocAuthCallback();
clbk.m_pxsInst = pSInt;
LIBNAME.IPXC_Document pDoc = pInst.OpenDocumentFromFile(sFilePath, clbk, null, 0, 0);
}
Btw, you can attach that sample to your message and we'll try to open it here.