Page 1 of 1

Core Api open document

Posted: Tue Sep 29, 2015 12:49 pm
by edvschu
Hello,

i try open a pdf with core api in .NET, but i get it not. How to instantiate DocAuthCallback? Online Help not help further.

I get following error: Error [Pdf Structure Library]: Unknown/unsupported security handler.

Code: Select all

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
Best Regards,
edvschu

Re: Core Api open document

Posted: Tue Sep 29, 2015 12:53 pm
by Sasha - Tracker Dev Team
Hi, edvschu

Please take a look here:
http://www.tracker-software.com/forum3/ ... 678#p94678

HTH

Re: Core Api open document

Posted: Tue Sep 29, 2015 1:05 pm
by edvschu
Thanks Sasha. But how i implement it in vb.net?

Re: Core Api open document

Posted: Tue Sep 29, 2015 1:33 pm
by Sasha - Tracker Dev Team
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.

Re: Core Api open document

Posted: Wed Sep 30, 2015 11:28 am
by edvschu
Sample in CSharp like in Editor SDK would me help, too :D.

Re: Core Api open document

Posted: Wed Sep 30, 2015 11:30 am
by Tracker Supp-Stefan
:)

Re: Core Api open document

Posted: Wed Sep 30, 2015 11:31 am
by Sasha - Tracker Dev Team
OK, that would be easier for us. We are working on this so stay tuned :wink:

Re: Core Api open document

Posted: Wed Sep 30, 2015 12:08 pm
by Sasha - Tracker Dev Team
OK so this is the first simple sample for document without password:

Code: Select all

private void OpenDocumentFromFileSample(string sFilePath, LIBNAME.IPXC_Inst pInst)
{
	LIBNAME.IPXC_Document pDoc = pInst.OpenDocumentFromFile(sFilePath, null, null, 0, 0);
}
We will post the version with the security handling later in this post.


HTH

Re: Core Api open document

Posted: Wed Sep 30, 2015 12:31 pm
by edvschu
Thanks for quick reply.

My Sample.pdf has no password. Try your code, i get same error message "Error [Pdf Structure Library]: ...".

Re: Core Api open document

Posted: Wed Sep 30, 2015 12:42 pm
by Sasha - Tracker Dev Team
Please send us the code of the error in 0xXXXXXXXX format so we can tell what is the problem.

Thanks,
Alex

Re: Core Api open document

Posted: Wed Sep 30, 2015 12:45 pm
by edvschu
Here the error code: 0x8214100F

Re: Core Api open document

Posted: Wed Sep 30, 2015 12:52 pm
by Sasha - Tracker Dev Team
We suspect that that document has security - do double check that please. Btw, security and passwords on the documents are two different things.

Re: Core Api open document  SOLVED

Posted: Wed Sep 30, 2015 12:55 pm
by Sasha - Tracker Dev Team
Here's the code for the password handling of the documents. But you must specify your correct password for each document.

Code: Select all

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.

HTH.

Re: Core Api open document

Posted: Wed Sep 30, 2015 2:05 pm
by edvschu
Arrrgh !!! Find my error. With IPXC_Inst.Init it works. Thanks Sasha for your help :D .

Re: Core Api open document

Posted: Wed Sep 30, 2015 2:05 pm
by Tracker Supp-Stefan
:)

Re: Core Api open document

Posted: Wed Sep 30, 2015 2:06 pm
by Sasha - Tracker Dev Team
Glad to hear that, edvschu. :wink: