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!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > I need help - I can help
  New Posts New Posts RSS Feed - AddImageFromString
  FAQ FAQ  Forum Search   Register Register  Login Login

AddImageFromString

 Post Reply Post Reply
Author
Message
eborger View Drop Down
Team Player
Team Player


Joined: 29 Apr 09
Location: Brazil
Status: Offline
Points: 33
Post Options Post Options   Thanks (0) Thanks(0)   Quote eborger Quote  Post ReplyReply Direct Link To This Post Topic: AddImageFromString
    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

Back to Top
tfrost View Drop Down
Senior Member
Senior Member


Joined: 06 Sep 10
Location: UK
Status: Offline
Points: 437
Post Options Post Options   Thanks (0) Thanks(0)   Quote tfrost Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
eborger View Drop Down
Team Player
Team Player


Joined: 29 Apr 09
Location: Brazil
Status: Offline
Points: 33
Post Options Post Options   Thanks (0) Thanks(0)   Quote eborger Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
tfrost View Drop Down
Senior Member
Senior Member


Joined: 06 Sep 10
Location: UK
Status: Offline
Points: 437
Post Options Post Options   Thanks (0) Thanks(0)   Quote tfrost Quote  Post ReplyReply Direct Link To This Post 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.

Back to Top
eborger View Drop Down
Team Player
Team Player


Joined: 29 Apr 09
Location: Brazil
Status: Offline
Points: 33
Post Options Post Options   Thanks (0) Thanks(0)   Quote eborger Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Ingo View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 29 Oct 05
Status: Offline
Points: 3524
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ingo Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
Ingo View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 29 Oct 05
Status: Offline
Points: 3524
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ingo Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
JanX View Drop Down
Beginner
Beginner
Avatar

Joined: 10 Oct 20
Location: Germany
Status: Offline
Points: 1
Post Options Post Options   Thanks (0) Thanks(0)   Quote JanX Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
tfrost View Drop Down
Senior Member
Senior Member


Joined: 06 Sep 10
Location: UK
Status: Offline
Points: 437
Post Options Post Options   Thanks (0) Thanks(0)   Quote tfrost Quote  Post ReplyReply Direct Link To This Post 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!
Back to Top
Ingo View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 29 Oct 05
Status: Offline
Points: 3524
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ingo Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store