How do you read pdf from Istream in V4?

This Forum is for the use of Software Developers requiring help and assistance for Tracker Software's PDF-Tools SDK of Library DLL functions(only) - Please use the PDF-XChange Drivers API SDK Forum for assistance with all PDF Print Driver related topics or PDF-XChange Viewer SDK if appropriate.

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

Post Reply
ap_mi
User
Posts: 47
Joined: Mon Aug 31, 2015 11:38 pm

How do you read pdf from Istream in V4?

Post 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.
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17771
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

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

Post by Tracker Supp-Stefan »

Hello ap_mi,

The method you need is PXCp_StreamReadData

Regards,
Stefan
ap_mi
User
Posts: 47
Joined: Mon Aug 31, 2015 11:38 pm

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

Post 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?
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17771
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

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

Post 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
ap_mi
User
Posts: 47
Joined: Mon Aug 31, 2015 11:38 pm

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

Post 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.
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17771
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

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

Post 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
ap_mi
User
Posts: 47
Joined: Mon Aug 31, 2015 11:38 pm

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

Post 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.
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17771
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

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

Post 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
ap_mi
User
Posts: 47
Joined: Mon Aug 31, 2015 11:38 pm

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

Post by ap_mi »

Thanks for the info.

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

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

Thanks again.
User avatar
Will - Tracker Supp
Site Admin
Posts: 6815
Joined: Mon Oct 15, 2012 9:21 pm
Location: London, UK
Contact:

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

Post 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,
If posting files to this forum, you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded.
Thank you.

Best regards

Will Travaglini
Tracker Support (Europe)
Tracker Software Products Ltd.
http://www.tracker-software.com
ap_mi
User
Posts: 47
Joined: Mon Aug 31, 2015 11:38 pm

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

Post 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: https://sdkhelp.pdf-xchange.com/vie ... etSecurity.

Thanks.
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3549
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

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

Post 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
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
ap_mi
User
Posts: 47
Joined: Mon Aug 31, 2015 11:38 pm

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

Post 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.
User avatar
Will - Tracker Supp
Site Admin
Posts: 6815
Joined: Mon Oct 15, 2012 9:21 pm
Location: London, UK
Contact:

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

Post by Will - Tracker Supp »

Hi ap_mi,

Please take a look at the online documentation, here:
https://sdkhelp.pdf-xchange.com/vie ... C_Document

HTH!
If posting files to this forum, you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded.
Thank you.

Best regards

Will Travaglini
Tracker Support (Europe)
Tracker Software Products Ltd.
http://www.tracker-software.com
ap_mi
User
Posts: 47
Joined: Mon Aug 31, 2015 11:38 pm

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

Post 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.
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17771
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

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

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

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

Post 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
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply