Page 1 of 1

How do you read pdf from Istream in V4?

Posted: Tue Sep 01, 2015 12:03 am
by ap_mi
I'm trying to find out how to read a pdf from an Istream, but the PDF-ToolsV4SDK documentation does not specify a function for this.

Any help on this would be appreciated.

Thanks in advance.

Re: How do you read pdf from Istream in V4?

Posted: Tue Sep 01, 2015 12:24 pm
by Tracker Supp-Stefan
Hello ap_mi,

The method you need is PXCp_StreamReadData

Regards,
Stefan

Re: How do you read pdf from Istream in V4?

Posted: Wed Sep 02, 2015 11:17 pm
by ap_mi
Thanks for your response Tracker Supp-Stefan.

Any idea how I can read from the Istream object and put it in _PXCDocument object?

Re: How do you read pdf from Istream in V4?

Posted: Thu Sep 03, 2015 12:56 pm
by Tracker Supp-Stefan
Hello ap_mi,

Did you take a look at the above page (the method name is a link)?
There you can see a code sample showing you how to use the stream and save it to file - then you can read the data from there.

Regards,
Stefan

Re: How do you read pdf from Istream in V4?

Posted: Thu Sep 03, 2015 3:59 pm
by ap_mi
hello,

Yeah I took a look, but I was wondering if this could be done without writing it to a file but just reading it from memory instead? I know that in a previous version of this library there existed a function called PXCV_ReadDocumentFromIStream that did this, but can't seem to find this functionality here.

Thanks again for your help.

Re: How do you read pdf from Istream in V4?

Posted: Fri Sep 04, 2015 8:00 am
by Tracker Supp-Stefan
Hello ap_mi,

PXCV_ReadDocumentFromIStream is part of the Viewer AX SDK, not the Tools SDK - so it's a different library and product all together.

Regards,
Stefan

Re: How do you read pdf from Istream in V4?

Posted: Tue Sep 08, 2015 8:14 pm
by ap_mi
Well...that makes sense now.

My end goal is to be able to apply pdf security for a pdf in memory without writing to disk. Would you happen to know if this is possible?

Thanks again for your help.

Re: How do you read pdf from Istream in V4?

Posted: Wed Sep 09, 2015 1:30 pm
by Tracker Supp-Stefan
Hello ap_mi,

I checked with a colleague, and he told me that this would be possible with the Core API - which is a new SDK which will be the successor of the current Tools SDK. We are planning the release to be later today so please do download it and give it a try once available.

Regards,
Stefan

Re: How do you read pdf from Istream in V4?

Posted: Wed Sep 09, 2015 9:34 pm
by ap_mi
Thanks for the info.

I checked for it today here: https://www.tracker-software.com/product/downloads/sdk

It looks like it hasn't become available yet, so I'll keep checking for it.

Thanks again.

Re: How do you read pdf from Istream in V4?

Posted: Wed Sep 09, 2015 9:37 pm
by Will - Tracker Supp
Hi ap_mi,

It should be released and available within the next few hours, but syncing the upload to our cloud can take quite a while. If you don't see it up in an hour or two, I'd check back tomorrow and it should be available (acts of god notwithstanding).

Cheers,

Re: How do you read pdf from Istream in V4?

Posted: Mon Sep 14, 2015 8:44 pm
by ap_mi
Hello,

How can I get an example on how to apply pdf security using the core sdk? It seems that the documentation is still incomplete.

I saw this function that might do the trick, but still unclear on how it works: http://sdkhelp.tracker-software.com/vie ... etSecurity.

Thanks.

Re: How do you read pdf from Istream in V4?

Posted: Tue Sep 15, 2015 10:47 pm
by Ivan - Tracker Software
This operation is not intended to be used without UI or with custom data as its parameters structure depends of security handler used.
If you want to secure document using UI (like in the end user Editor), you need to:
1. create an operation;
2. call its ShowSetupUI
3. and if user press OK, launch the operation (call Do method)

Or you can use SetStdEncryption method of IPXC_Document.
Please note, new security settings will be used after document save.

Here is sample code (C++):

Code: Select all

pDoc->SetStdEncryption(SEM_AV10, VARIANT_TRUE, PermF_User - PermF_Edit - PrivPermF_DocAssembly, L"111", L"123");
That protects document with specified passwords and disable editing of the document.

HTH

Re: How do you read pdf from Istream in V4?

Posted: Wed Sep 16, 2015 6:38 pm
by ap_mi
I'm trying to call IPXC_Document.LoadContent which requires two pointers to IPXS_PDFVariant. How do I instantiate/create a IPXS_PDFVariant interface?

Actually, would it be possible for you to give me a complete example on how one would load a pdf into IPXC_Document?

Thanks for your help.

Re: How do you read pdf from Istream in V4?

Posted: Thu Sep 17, 2015 9:39 pm
by Will - Tracker Supp
Hi ap_mi,

Please take a look at the online documentation, here:
http://sdkhelp.tracker-software.com/vie ... C_Document

HTH!

Re: How do you read pdf from Istream in V4?

Posted: Fri Sep 18, 2015 3:25 pm
by ap_mi
Yes, I've seen the online documentation. The documentation does not seem very complete and is lacking examples at this point in time. The documentation essentially contains a list of functions for each object/interface with hardly any description on the parameters for the methods nor any examples on how to instantiate many of the interface types.

Would it be possible for anyone here to go a little beyond this documentation and provide me a full example of how one would load a pdf document into IPXC_Document? More specifically, an example that instantiates all the objects and calls all the methods needed in order to load a pdf into IPXC_Document (in C++ preferably).

I'm assuming one would just need to call IPXC_Document.LoadContent() function, but like I mentioned earlier, there's hardly any description for the parameters nor how to instantiate the objects needed to pass arguments to this function.

Thanks.

Re: How do you read pdf from Istream in V4?

Posted: Mon Sep 21, 2015 10:24 am
by Tracker Supp-Stefan
Hello ap_mi,

I've asked colleagues from the dev team to help us here with an example. As soon as we can - we will post it here.

Regards,
Stefan

Re: How do you read pdf from Istream in V4?

Posted: Tue Sep 22, 2015 7:18 am
by Sasha - Tracker Dev Team
Hi, ap_mi.

How to load a pdf document into the IPXC_Document:

Code: Select all

//Class of the callback for the document authorization (if you don't have any documents with passwords you don't need it)
class ATL_NO_VTABLE CDocAuthCallbackImpl : public CComObjectRootEx<CComSingleThreadModel>, public ATL::IDispatchImpl<IPXC_DocAuthCallback, &__uuidof(IPXC_DocAuthCallback)>
{
public:
	CDocAuthCallbackImpl() {}
	~CDocAuthCallbackImpl() {}
public:
	DECLARE_PROTECT_FINAL_CONSTRUCT()

	BEGIN_COM_MAP(CDocAuthCallbackImpl)
		COM_INTERFACE_ENTRY(IPXC_DocAuthCallback)
		COM_INTERFACE_ENTRY(IDispatch)
	END_COM_MAP()
public:
	STDMETHODIMP AuthDoc(IPXC_Document* pDoc, ULONG_T nFlags) override
	{
		if (!pDoc || !m_pxsInst)
			return E_INVALIDARG;
		//Checking whether the document has any security
		ULONG_T nNameAtom = 0;
		pDoc->GetSecurityHandlerType(VARIANT_FALSE, &nNameAtom);
		if (nNameAtom == 0)
		{
			//No security so successfully opened doc
			//...
			return S_OK;
		}
		//Else we must provide a password
		ULONG_T nStandard = 0;
		m_pxsInst->StrToAtom(L"Standard", &nStandard);
		PXC_PermStatus status = Perm_ReqGranted;
		//Comparing whether the security handler type is Standard
		if (nStandard != nNameAtom)
		{
			//We do not support this one
			return E_INVALIDARG;
		}

		pDoc->AuthorizeWithPassword(L"YourPasswordHere", &status);
		if (status != Perm_ReqGranted)
		{
			//We don't have permission to open doc
			return E_FAIL;
		}
		return S_OK;
	}
public:
	IPXS_Inst*			m_pxsInst = nullptr;
};

HRESULT OpenDocumentFromFileSample(LPCWSTR sFilePath, IPXC_Inst* pInst)
{
	if (pInst == nullptr)
		return E_INVALIDARG;
	//Getting IPXS_Inst if you don't have it
	IPXS_Inst* pSInst = nullptr;
	IUnknown* pUnk = nullptr;
	pInst->GetExtension(L"PXS", &pUnk);
	if (pUnk)
		pUnk->QueryInterface(&pSInst);
	if (pSInst == nullptr)
		return E_FAIL;

	HRESULT hr = S_OK;
	IPXC_Document* pDoc = nullptr;
	do
	{
		CComObject<CDocAuthCallbackImpl>* pCoObj;// Callback where the AuthDoc function should be implemented for authorization if some of your documents have password protection else - nullptr as default
		hr = CComObject<CDocAuthCallbackImpl>::CreateInstance(&pCoObj);
		if (hr != S_OK)
			break;
		pCoObj->AddRef();
		pCoObj->m_pxsInst = pSInst;
		//Opening document from file with given file name with default parameters
		hr = pInst->OpenDocumentFromFile(sFilePath, pCoObj, nullptr, 0, 0, &pDoc);
		pCoObj->Release();
		if (hr != S_OK)
			break;

		//Successfully opened doc
		//...
	} while (false);

	pSInst->Release();
	if (pDoc)
		pDoc->Release();

	return hr;
}

HTH