Print Page | Close Window

AddImageFromString

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=3942
Printed Date: 03 May 24 at 8:33AM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: AddImageFromString
Posted By: eborger
Subject: AddImageFromString
Date Posted: 24 Jul 21 at 6:15PM
Hello,

I am trying to use the AddImageFromString function, but get a 0 result (error), what kind of string should this be ? 
I loaded a BMP and a JPG file into memory, but it does not work, can you help me ?

thank you,
Edgar




Replies:
Posted By: tfrost
Date Posted: 24 Jul 21 at 7:17PM
If you have the images as files, have you already tried AddImageFromFile?  If this works, then you have ruled out any problem about  the data.  If there is some reason why you cannot use files in your application, then how you build the string depends on what programming language you are using, which you have not said.


Posted By: eborger
Date Posted: 24 Jul 21 at 9:32PM
with AddImageFromFile it works fine, so the question is how should the string be built ?
I am using Xbase++ language which is C++ based, and calling the DLL version of the lib.
Is there a prefix to the string ? what is the valid format of the string ?

Thanks,
Edgar


Posted By: tfrost
Date Posted: 25 Jul 21 at 10:58AM
I have never used this function (and never want to, after looking into it), so all I know is what is in the documentation and what the Delphi IDE tells me. For Delphi, the DCU object file (QPDF  18) says the parameter is a WideString, but in the (QPDF 16) source code that I no longer use it is declared as an AnsiString and moved directly into a memorystream for use. This is one reason why it is not worth my experimenting in Delphi, because would be is simpler to use ...fromStream and be certain, if I needed this functionality!

For the ActiveX version, the QPDF 18 documentation makes clear that it is a string of 16-bit characters, and that only the low 8 bits of each character are used. So this function needs work to create its parameter from real-world image data, before you can call it in this way.

For the DLL version the C++ header (QPDF 18) declares the parameter as a string, not a wstring. Your guess is as good as mine as to the format it expects, but I would try pointing it at a simple array of bytes containing the file contents. Of course this data may contain byte values of zero, so it is not really a null-terminated string.



Posted By: eborger
Date Posted: 25 Jul 21 at 5:52PM
For the DLL version the C++ header (QPDF 18) declares the parameter as a string, not a wstring. Your guess is as good as mine as to the format it expects, but I would try pointing it at a simple array of bytes containing the file contents. Of course this data may contain byte values of zero, so it is not really a null-terminated string.

this is what I did, and I get an 0 (error) return .... so I guess it must have some kind of header or something.... I will try contacting support...
Thanks


Posted By: Ingo
Date Posted: 26 Jul 21 at 10:06PM
instead you should try LastErrorCode directly after the function call.
Perhaps then you'll get a more detailed info about the error.



-------------
Cheers,
Ingo



Posted By: Ingo
Date Posted: 26 Jul 21 at 10:11PM
These three threads will give you an idea how to do it the right way:
http://www.quickpdf.org/forum/c-using-addimagefromstring-with-drawingimaging_topic2308.html
http://www.quickpdf.org/forum/addimagefromstring-in-c-dll-project-resolved_topic2144.html
https://www.debenu.com/kb/how-do-i-programmatically-create-thumbnails-for-pages-in-pdfs/



-------------
Cheers,
Ingo



Posted By: JanX
Date Posted: 30 Jul 21 at 7:51PM
Hi,

I jump into this thread for I face the same problem as Edgar. And I tried LastErrorCode() as suggested, but that also returns a 0.

The point is: AddImageFromFile() works like a charme. But what I do (please don't discuss this) is that the picture is stored in a binary table field. The character set of this table is ANSI. When creating the PDF file I read the string from the table. And I want to add this string to the pdf without the detour storing this string to a temp file and adding this to the PDF via AddImageFromFile().

So: When AddImageFromFile() (and all other function calls I do) is working, but AddImageFromString() and LastErrorCode() both return a 0 - what's wrong?

JanX


Posted By: tfrost
Date Posted: 30 Jul 21 at 9:08PM
The links that Ingo posted confirm my feeling that the problem is much more likely to arise in preparing the 'string', and not in QPDF itself.  The key to passing the data to QPDF is never to treat it as a 'string'.  It is just a block of bytes. If you ever give the compiler a chance to treat it as a string, C or C++ functions will stop processing at the first null byte (and there are many of these in an image). So my feeling is that if you really 'read a string from the table' you will end up with only a tiny piece of it; the rest will have disappeared already, before you even try to pass it to QPDF.  You should treat it always as an array of bytes, and only use 'string' when you cast the pointer to pass to QPDF.  But I never use C with QPDF, so do not have personal experience of this problem!


Posted By: Ingo
Date Posted: 31 Jul 21 at 3:14PM
From my opinion opening an image with notepad should give me the same view than look directly into your string content. Are there differences?
BTW: There's another function called AddImageFromStream available...



-------------
Cheers,
Ingo




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