Core Api open document  SOLVED

A forum for questions or concerns related to the PDF-XChange Core API SDK

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Tracker Supp-Stefan

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.
Post Reply
edvschu
User
Posts: 127
Joined: Fri Jun 25, 2010 6:54 am

Core Api open document

Post 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
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Core Api open document

Post by Sasha - Tracker Dev Team »

Hi, edvschu

Please take a look here:
https://forum.pdf-xchange.com/ ... 678#p94678

HTH
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
edvschu
User
Posts: 127
Joined: Fri Jun 25, 2010 6:54 am

Re: Core Api open document

Post by edvschu »

Thanks Sasha. But how i implement it in vb.net?
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Core Api open document

Post 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.
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
edvschu
User
Posts: 127
Joined: Fri Jun 25, 2010 6:54 am

Re: Core Api open document

Post by edvschu »

Sample in CSharp like in Editor SDK would me help, too :D.
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17820
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Core Api open document

Post by Tracker Supp-Stefan »

:)
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Core Api open document

Post by Sasha - Tracker Dev Team »

OK, that would be easier for us. We are working on this so stay tuned :wink:
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Core Api open document

Post 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
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
edvschu
User
Posts: 127
Joined: Fri Jun 25, 2010 6:54 am

Re: Core Api open document

Post by edvschu »

Thanks for quick reply.

My Sample.pdf has no password. Try your code, i get same error message "Error [Pdf Structure Library]: ...".
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Core Api open document

Post 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
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
edvschu
User
Posts: 127
Joined: Fri Jun 25, 2010 6:54 am

Re: Core Api open document

Post by edvschu »

Here the error code: 0x8214100F
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Core Api open document

Post 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.
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Core Api open document  SOLVED

Post 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.
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
edvschu
User
Posts: 127
Joined: Fri Jun 25, 2010 6:54 am

Re: Core Api open document

Post by edvschu »

Arrrgh !!! Find my error. With IPXC_Inst.Init it works. Thanks Sasha for your help :D .
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17820
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Core Api open document

Post by Tracker Supp-Stefan »

:)
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Core Api open document

Post by Sasha - Tracker Dev Team »

Glad to hear that, edvschu. :wink:
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply