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() in C++ DLL Project (RESOLVED)
  FAQ FAQ  Forum Search   Register Register  Login Login

AddImageFromString() in C++ DLL Project (RESOLVED)

 Post Reply Post Reply
Author
Message Reverse Sort Order
barqyDev View Drop Down
Beginner
Beginner


Joined: 10 Feb 12
Status: Offline
Points: 7
Post Options Post Options   Thanks (0) Thanks(0)   Quote barqyDev Quote  Post ReplyReply Direct Link To This Post Topic: AddImageFromString() in C++ DLL Project (RESOLVED)
    Posted: 11 Feb 12 at 8:03AM
Thank you for your reply today, it helped!

Unfortunately, I remained my own worst enemy.  After the the RCDATA update, I was getting the data and length right, but it wasn't working.

After dinner I came back and took a look at the actual call to AddImageFromString() that I was making.  Turns out I wasn't getting all the data stuffed into the std::string I thought I was.  I only got the first chunk of bytes up to the first NULL.

Builidng my input parameter with this helped: std::string test( res_data, res_size );

So....Here's the working code block for anybody else that might stroll by:

      int result = 0;
      HINSTANCE Instance = AfxGetInstanceHandle();
      HRSRC res = FindResource( Instance,MAKEINTRESOURCE( IDB_BINARY ), RT_RCDATA );
      if( res )
      {
         HGLOBAL res_handle = LoadResource( Instance , res );
         if( res_handle )
         {
            char *res_data = (char *) LockResource( res_handle );
            if( res_data )
            {
               DWORD res_size = SizeofResource( Instance, res );
               if( res_size )
               {
                  std::string test( res_data, res_size );
                  result = m_PdfWriter->AddImageFromString( test, 0 );
                  m_PdfWriter->SelectImage( result );
                  m_PdfWriter->DrawImage( 550, 5, 60, 60 );
               } // got the length
            } // locked it..i.e. got pointer to 1st byte
         } // loaded the resource
      } // found the resource item

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

Joined: 08 Dec 10
Location: Geelong, Aust
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote AndrewC Quote  Post ReplyReply Direct Link To This Post Posted: 11 Feb 12 at 2:13AM
AddImage from file expects a full BMP, JPG, PNG or TIFF file.  It sounds like you are on the right track extracting the JPEG resource.

Here is a post that gives some hope.  The last reply indicates that it might work better when the JPG is marked as RCDATA in the resource file.

Back to Top
barqyDev View Drop Down
Beginner
Beginner


Joined: 10 Feb 12
Status: Offline
Points: 7
Post Options Post Options   Thanks (0) Thanks(0)   Quote barqyDev Quote  Post ReplyReply Direct Link To This Post Posted: 10 Feb 12 at 10:24PM
Another update....loaded a JPG from disk into a PDF file:
CImage image;
image.LoadFromResource( AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_LOGO)  );
image.Save( L"test.jpg" );
index = pdf.AddImageFromFile( L"test.jpg", 0 );
pdf.SelectImage( index );
pdf.DrawImage( 0, 0, 100, 100 );
// all that above works

// now, let's what data got stuffed into the PDF
index = pdf.GetPageImageList(0);
std::string Grab = pdf.GetImageListItemDataToString( index, 1, 0 );
// and it looks like the exact same content as what's in my JPG file on disk.


Assuming I have that right, I'm now chunking through some more API calls:
FindResource
LoadResource
LockResource
SizeofResource

Hopefully I'm on the right track.
Back to Top
barqyDev View Drop Down
Beginner
Beginner


Joined: 10 Feb 12
Status: Offline
Points: 7
Post Options Post Options   Thanks (0) Thanks(0)   Quote barqyDev Quote  Post ReplyReply Direct Link To This Post Posted: 10 Feb 12 at 9:19PM
I do have a working project using AddImageFromFile() it just makes me unhappy for the reasons mentioned.
Back to Top
barqyDev View Drop Down
Beginner
Beginner


Joined: 10 Feb 12
Status: Offline
Points: 7
Post Options Post Options   Thanks (0) Thanks(0)   Quote barqyDev Quote  Post ReplyReply Direct Link To This Post Posted: 10 Feb 12 at 8:30PM
I'm using Visual Studio 2010 in a MFC Dialog App and I would like to be able to 
place images in my PDF that come from bitmaps stored in my resource file

reason 1 - don't want to have files travelling with the app.  I'd like it as standalone as possible
reason 2 - don't want to create temporary files on disk just to load with AddImageFromFile()

I've tried loading the image into memory with CImage:
CImage Image;
 Image.LoadFromResource( AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_VESSIX) );

I have access to the bitmap data via Image.GetBits(), but it's not clear to me
what format data AddImageFromString() actually wants.

I know it takes a std::string parameter, but that doesn't say what it's expecting.

Any help would be appreciated!



Edited by barqyDev - 11 Feb 12 at 8:04AM
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