op.document.exportToImages

From PDF XChange PDF SDK
Jump to: navigation, search
(Sample)
Line 62: Line 62:
 
</pre>
 
</pre>
  
== Sample ==
+
<pre class="brush:cpp">//C++
<pre>//C++
+
 
HRESULT ExportToImages(PXV::IPXV_Document pDoc, PXV::IPXV_Inst pInst)
 
HRESULT ExportToImages(PXV::IPXV_Document pDoc, PXV::IPXV_Inst pInst)
 
{
 
{

Revision as of 06:46, 22 February 2016


Overview

The operation allows to export document pages to the image files with given DPI, zoom factor and specified format.

Parameters

Name Type Description
Input Array Array of IUnknown-based objects.
Output Array Array of IUnknown-based objects.
Options Dictionary Dictionary with options of the operation.

Sample

//C#
private void ExportToImages(PDFXEdit.IPXV_Document Doc, PDFXEdit.PXV_Inst Inst)
{
	int nID = Inst.Str2ID("op.document.exportToImages", false);
	PDFXEdit.IOperation Op = Inst.CreateOp(nID);
	PDFXEdit.ICabNode input = Op.Params.Root["Input"];
	input.Add().v = Doc;
	PDFXEdit.ICabNode options = Op.Params.Root["Options"];
	options["PagesRange.Type"].v = "Exact";
	options["PagesRange.Text"].v = "1-3";
	options["DestFolder"].v = "D:\\TestFolder\\"; //Output folder
	options["ExportMode"].v = "AllToMutliPage";
	options["Zoom"].v = 150;
	//Saving as tiff
	PDFXEdit.ICabNode fmtParams = options["FormatParams"];
	//Compression type
	fmtParams["COMP"].v = 5; //LZW compression
	//X DPI
	fmtParams["DPIX"].v = 150;
	//Y DPI
	fmtParams["DPIY"].v = 150;
	//Image format
	fmtParams["FMT"].v = 1414088262; //TIFF
	//Image type
	fmtParams["ITYP"].v = 16; //24 TrueColor
	//Use Predictor
	fmtParams["PRED"].v = 1; //Yes
	//Thumbnail
	fmtParams["ITYP"].v = 0; //No

	Op.Do();
}
//C++
HRESULT ExportToImages(PXV::IPXV_Document pDoc, PXV::IPXV_Inst pInst)
{
	if ((pDoc == nullptr) || (pInst == nullptr))
		return E_FAIL;
	HRESULT hr = S_OK;
	//Export to images
	do
	{
		LONG opID = -1;
		pInst->Str2ID(L"op.document.exportToImages", false, &opID);
		if (opID < 0)
			break;
		CComPtr<PXV::IOperation> pOp;
		hr = pInst->CreateOp(opID, &pOp);
		if (FAILED(hr))
			break;
		//Getting parameters
		CComPtr<PXV::ICab> pParams;
		hr = pOp->get_Params(&pParams);
		if (FAILED(hr))
			break;
		CComPtr<PXV::ICabNode> pRoot;
		hr = pParams->get_Root(&pRoot);
		if (FAILED(hr))
			break;
		//Setting input document
		CComPtr<PXV::ICabNode> pInput;
		hr = pRoot->get_SubNode(CComVariant("Input"), PXV::dt_Array, &pInput);
		if (FAILED(hr))
			break;
		CComPtr<PXV::ICabNode> pDocNode;
		hr = pInput->Add(PXV::dt_IUnknown, &pDocNode);
		if (FAILED(hr))
			break;
		hr = pDocNode->put_Unknown(pVDoc);
		if (FAILED(hr))
			break;

		//Setting options
		CComPtr<PXV::ICabNode> pOptions;
		hr = pRoot->get_SubNode(CComVariant("Options"), PXV::dt_Undefined, &pOptions);
		if (FAILED(hr))
			break;
		pOptions->SetString(L"PagesRange.Type", L"Exact");
		pOptions->SetString(L"PagesRange.Text", L"1-3");
		pOptions->SetString(L"DestFolder", L"D:\\TestFolder\\");
		pOptions->SetString(L"ExportMode", L"AllToMutliPage");
		pOptions->SetInt(L"Zoom", 150);
		//Image format parameters
		CComPtr<PXV::ICabNode> pFmtParams;
		hr = pOptions->get_SubNode(CComVariant("FormatParams"), PXV::dt_Undefined, &pFmtParams);
		if (FAILED(hr))
			break;
		//Compression type
		pFmtParams->SetInt(L"COMP", 5); //LZW compression
		//X DPI
		pFmtParams->SetInt(L"DPIX", 150);
		//Y DPI
		pFmtParams->SetInt(L"DPIY", 150);
		//Image format
		pFmtParams->SetInt(L"FMT", 1414088262); //TIFF
		//Image type
		pFmtParams->SetInt(L"ITYP", 16); //24 TrueColor
		//Use Predictor
		pFmtParams->SetInt(L"PRED", 1); //Yes
		//Thumbnail
		pFmtParams->SetInt(L"ITYP", 0); //No

		hr = pOp->Do(0);

	} while (false);
	return hr;
}