Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!
![]() |
AddImageFromString |
Post Reply ![]() |
Author | |
eborger ![]() Team Player ![]() Joined: 29 Apr 09 Location: Brazil Status: Offline Points: 33 |
![]() ![]() ![]() ![]() ![]() 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 |
|
![]() |
|
tfrost ![]() Senior Member ![]() Joined: 06 Sep 10 Location: UK Status: Offline Points: 437 |
![]() ![]() ![]() ![]() ![]() |
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.
|
|
![]() |
|
eborger ![]() Team Player ![]() Joined: 29 Apr 09 Location: Brazil Status: Offline Points: 33 |
![]() ![]() ![]() ![]() ![]() |
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
|
|
![]() |
|
tfrost ![]() Senior Member ![]() Joined: 06 Sep 10 Location: UK Status: Offline Points: 437 |
![]() ![]() ![]() ![]() ![]() |
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. |
|
![]() |
|
eborger ![]() Team Player ![]() Joined: 29 Apr 09 Location: Brazil Status: Offline Points: 33 |
![]() ![]() ![]() ![]() ![]() |
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
|
|
![]() |
|
Ingo ![]() Moderator Group ![]() ![]() Joined: 29 Oct 05 Status: Offline Points: 3529 |
![]() ![]() ![]() ![]() ![]() |
instead you should try LastErrorCode directly after the function call.
Perhaps then you'll get a more detailed info about the error. |
|
Cheers,
Ingo |
|
![]() |
|
Ingo ![]() Moderator Group ![]() ![]() Joined: 29 Oct 05 Status: Offline Points: 3529 |
![]() ![]() ![]() ![]() ![]() |
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 |
|
![]() |
|
JanX ![]() Beginner ![]() ![]() Joined: 10 Oct 20 Location: Germany Status: Offline Points: 1 |
![]() ![]() ![]() ![]() ![]() |
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
|
|
![]() |
|
tfrost ![]() Senior Member ![]() Joined: 06 Sep 10 Location: UK Status: Offline Points: 437 |
![]() ![]() ![]() ![]() ![]() |
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!
|
|
![]() |
|
Ingo ![]() Moderator Group ![]() ![]() Joined: 29 Oct 05 Status: Offline Points: 3529 |
![]() ![]() ![]() ![]() ![]() |
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 |
|
![]() |
Post Reply ![]() |
|
Tweet
|
Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store