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() in C++ DLL Project (RESOLVED) |
Post Reply |
Author | |
barqyDev
Beginner Joined: 10 Feb 12 Status: Offline Points: 7 |
Post Options
Thanks(0)
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 |
|
AndrewC
Moderator Group Joined: 08 Dec 10 Location: Geelong, Aust Status: Offline Points: 841 |
Post Options
Thanks(0)
|
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. |
|
barqyDev
Beginner Joined: 10 Feb 12 Status: Offline Points: 7 |
Post Options
Thanks(0)
|
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.
|
|
barqyDev
Beginner Joined: 10 Feb 12 Status: Offline Points: 7 |
Post Options
Thanks(0)
|
I do have a working project using AddImageFromFile() it just makes me unhappy for the reasons mentioned.
|
|
barqyDev
Beginner Joined: 10 Feb 12 Status: Offline Points: 7 |
Post Options
Thanks(0)
|
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 |
|
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