op.document.exportToImages

From PDF XChange PDF SDK
Jump to: navigation, search
(Sample)
 
Line 63: Line 63:
  
 
<pre class="brush:cpp">//C++
 
<pre class="brush:cpp">//C++
 +
#define MAKE_ID(a, b, c, d) ((a) << 24) | ((b) << 16) | ((c) << 8) | (d)
 +
 +
#define FMT_BMP_ID MAKE_ID('B', 'M', 'P', ' ')
 +
#define FMT_GIF_ID MAKE_ID('G', 'I', 'F', ' ')
 +
#define FMT_TIFF_ID MAKE_ID('T', 'I', 'F', 'F')
 +
#define FMT_JPG_ID MAKE_ID('J', 'P', 'G', ' ')
 +
#define FMT_PNG_ID MAKE_ID('P', 'N', 'G', ' ')
 +
 
HRESULT ExportToImages(PXV::IPXV_Document* pVDoc, PXV::IPXV_Inst* pInst)
 
HRESULT ExportToImages(PXV::IPXV_Document* pVDoc, PXV::IPXV_Inst* pInst)
 
{
 
{
Line 123: Line 131:
 
pFmtParams->SetInt(L"DPIY", 150);
 
pFmtParams->SetInt(L"DPIY", 150);
 
//Image format
 
//Image format
pFmtParams->SetInt(L"FMT", 1414088262); //TIFF
+
pFmtParams->SetInt(L"FMT", FMT_TIFF_ID); //TIFF
 
//Image type
 
//Image type
 
pFmtParams->SetInt(L"ITYP", 16); //24 TrueColor
 
pFmtParams->SetInt(L"ITYP", 16); //24 TrueColor

Latest revision as of 15:04, 25 November 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["THUM"].v = 0; //No

	Op.Do();
}
//C++
#define MAKE_ID(a, b, c, d)		((a) << 24) | ((b) << 16) | ((c) << 8) | (d)

#define FMT_BMP_ID			MAKE_ID('B', 'M', 'P', ' ')
#define FMT_GIF_ID			MAKE_ID('G', 'I', 'F', ' ')
#define FMT_TIFF_ID			MAKE_ID('T', 'I', 'F', 'F')
#define FMT_JPG_ID			MAKE_ID('J', 'P', 'G', ' ')
#define FMT_PNG_ID			MAKE_ID('P', 'N', 'G', ' ')

HRESULT ExportToImages(PXV::IPXV_Document* pVDoc, PXV::IPXV_Inst* pInst)
{
	if ((pVDoc == 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", FMT_TIFF_ID); //TIFF
		//Image type
		pFmtParams->SetInt(L"ITYP", 16); //24 TrueColor
		//Use Predictor
		pFmtParams->SetInt(L"PRED", 1); //Yes
		//Thumbnail
		pFmtParams->SetInt(L"THUM", 0); //No

		hr = pOp->Do(0);

	} while (false);
	return hr;
}