Frequently Asked Question:
How do I use an unsigned char* string with the LoadFromString function?
Question
How do I use an unsigned char* string with the LoadFromString function?
Answer
The client wrapper class' LoadFromString function accepts a std::string which can contain binary data. The trick is to convert the unsigned char data that you have into a std::string. The following C++ example should do the trick. It's tested and seems to work okay.
// Open the file
FILE *fileHandle = fopen("test.pdf", "rb");
// Get the length of the file
fseek(fileHandle, 0, SEEK_END);
long fileLength = ftell(fileHandle);
// Go back to the beginning
fseek(fileHandle, 0, SEEK_SET);
// Allocate some memory using unsigned char
unsigned char *fileBytes = (unsigned char *)malloc(fileLength);
// Read the file contents
fread(fileBytes, fileLength, 1, fileHandle);
fclose(fileHandle);
// Convert the unsigned char array into a std::string
std::string fileBytesStr = std::string(
reinterpret_cast<char*>(fileBytes), fileLength);
// Create an instance of the Quick PDF Library DLL interface class
QuickPDFDLL0716 QP("D:\\QPL\\QuickPDFDLL0716.dll");
// Unlock the library
QP.UnlockKey("jj9a947m5u14zp6cg87f9nj3y");
int loadResult = QP.LoadFromString(fileBytesStr);
if (loadResult == 1)
{
// Success
}
else
{
// Failure
}