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, Sean - Tracker, Chris - Tracker Supp, 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 » Tue Sep 01, 2015 12:03 am

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: 13663
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 » Tue Sep 01, 2015 12:24 pm

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 » Wed Sep 02, 2015 11:17 pm

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: 13663
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 » Thu Sep 03, 2015 12:56 pm

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 » Thu Sep 03, 2015 3:59 pm

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: 13663
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 » Fri Sep 04, 2015 8:00 am

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 » Tue Sep 08, 2015 8:14 pm

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: 13663
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 » Wed Sep 09, 2015 1:30 pm

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 » Wed Sep 09, 2015 9:34 pm

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.

User avatar
Will - Tracker Supp
Site Admin
Posts: 6819
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 » Wed Sep 09, 2015 9:37 pm

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 » Mon Sep 14, 2015 8:44 pm

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.

Ivan - Tracker Software
Site Admin
Posts: 3611
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 » Tue Sep 15, 2015 10:47 pm

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 » Wed Sep 16, 2015 6:38 pm

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: 6819
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 » Thu Sep 17, 2015 9:39 pm

Hi ap_mi,

Please take a look at the online documentation, here:
http://sdkhelp.tracker-software.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 » Fri Sep 18, 2015 3:25 pm

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: 13663
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 » Mon Sep 21, 2015 10:24 am

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

User avatar
Sasha - Tracker Dev Team
User
Posts: 4532
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 » Tue Sep 22, 2015 7:18 am

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
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

Post Reply