Obtain File Format Information
File Content Extraction allows you to obtain the following basic information for a file:
- The character set. See the
KVCharSetenumerated type. - The class of document. See the
ENdocClassenumerated type. - The specific type of document. See the
ENdocFmtenumerated type. - Some other attributes such as the presence of encryption. See the
ENdocAttributesenumerated type.
You can obtain the file format information by using the fpGetFileInfo() function pointer.
You call fpGetFileInfo() with the path to the file, and a pointer to a KVDocInfo structure that File Content Extraction can fill with the file details. For more details about the fpGetFileInfo() function pointer, see C API Reference.
Get the Types of Files in a List
The following example illustrates how to:
- obtain function pointers by calling
KVPDFGetInterface. The pointer to this method is passed into the function asfpGetInterfacein this example. You need this pointer to get other function pointers, includingfpInit(), which must be called first, andfpShutdown(), which must be called last. For details of how to obtain this pointer, see Get a Session Context. - initialize File Content Extraction using
fpInit. - use the
fpGetFileInfo()method for each path in an array of file names (ppszFileNamesin this example). The file types output are put in thepeFileTypesOutputarray of enumerated typeENdocFmt. - shut down File Content Extraction by calling
fpShutdown().
NOTE: If a call to fpGetFileInfo is unsuccessful, the KVDocInfo structure is not modified. The return value of fpGetFileInfo is therefore ignored in this example because the KVDocInfo structure is left zero-filled with the character set equal to KVCS_UNKNOWN, the document class to set to AutoDetNoFormat, and the file type of Unknown_Fmt.
#include "kvpdf.h"
void getTypesOfFilesInList(
const KVPDFInterface sInterface,
const char* const pszKeyViewDir,
const char* const pszTempFolder,
const char* const pszLicense,
const char* const * const ppszFileNames,
ENdocFmt* const peFileTypesOutput,
const unsigned int numberOfFiles)
{
KVPDFContext context = NULL;
unsigned int i = 0;
if(sInterface.fpInit(
pszKeyViewDir, pszTempFolder, pszLicense, &context
).eErrorCode != KVERR_Success)
{
return;
}
for (i = 0; i < numberOfFiles; i++)
{
// (ENdocFmt) 0 = Unknown_Fmt
KVDocInfo sDocInfo = {0};
sInterface.fpGetFileInfo(context, ppszFileNames[i], &sDocInfo);
peFileTypesOutput[i] = sDocInfo.adInfo.eFormat;
}
sInterface.fpShutDown(&context);
}