Print Page | Close Window

DPLLoadFromString Fails

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: Sample Code
Forum Description: Share Debenu Quick PDF Library sample code with other forum members
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=2511
Printed Date: 22 Nov 24 at 6:48PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: DPLLoadFromString Fails
Posted By: Xan
Subject: DPLLoadFromString Fails
Date Posted: 23 Jan 13 at 11:11PM
Hello,

I'm using QuickPDF Library as a LIB, building a DLL to be a browser plugin.  It works great overall.  Right now, I'm taking in a Base64-encoded PDF as input, decoding it, writing that file to a temporary file, and then loading that with DPLLoadFromFile.

It would be really nice to use DPLLoadFromString, since I have a std::string containing the Base64-decoded data, but I can't get it to work.  The call to DPLLoadFromString always returns 0.

I've tried several machinations, but here's what I believe ought to work.  Can anybody help?
DPLLoadFromString(InstanceID, const_cast<char *>(decoded_content.c_str()), L"");







Replies:
Posted By: AndrewC
Date Posted: 24 Jan 13 at 7:00AM
I see you are using C++.  The word string is a little confusing as it actually refers to a Delphi AnsiString which is a little different to a char pointer.

I suggest you read the final comment in the following thread.  It shows how to create an AnsiString buffer which can be used with LoadFromString.

http://www.quickpdf.org/forum/using-qpl8xx-with-realbasic-realstudio_topic2315.html

int BufferID , Test , ImageID;

BufferID = QPDFCreateBuffer ( InstanceID , buffer.Size )
if (BufferID != 0)  // OK
{
    Test = QPDFAddToBuffer (InstanceID , BufferID , buf, sizeof(buf));

    QPDFLoadFromFromString (InstanceID,  BufferID , "");

    Test = QPDFReleaseBuffer ( InstanceID,  BufferID )
}



Posted By: Xan
Date Posted: 24 Jan 13 at 5:01PM
Thank you very much!  It now works.  Here's the C++ version, in case anybody stumbles across this.


char * buffer = DPLCreateBuffer(InstanceID, decoded_content.length());
if(buffer == 0)
{ return "Unable to create buffer"; }
DPLAddToBuffer(InstanceID, buffer, const_cast<char *>(decoded_content.c_str()), decoded_content.length());
if(DPLLoadFromString(InstanceID, buffer, L"") == 0)
{
    DPLReleaseBuffer(InstanceID, buffer);
    return "Unable to load PDF";
}
DPLReleaseBuffer(InstanceID, buffer);




Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk