BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Converting HTML page from TCppWebBrowser into Image

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Internet Web)
View previous topic :: View next topic  
Author Message
Trevor Keegan
Guest





PostPosted: Tue Feb 06, 2007 8:13 am    Post subject: Converting HTML page from TCppWebBrowser into Image Reply with quote



Hi,

I have been looking at some code from that describes how to convert a HTML
page into an image (http://starkravingfinkle.org/blog/2004/09/). The
problem is before I get started, I see code like:
IHTMLDocument2 * pDoc = ....;
IHTMLELEMENT * pBodyElement = 0
HRESULT hr = pDoc->get_body(&pBodyElement);
if( SUCCEED(hr))
{
IHTMLElement * pBody = 0;
hr = pBodyElem - >QueryInterface( IID_IHTMLBodyElement,
(void**)&bBody );
:
:
}

The problem is I do not know what variables like amp and gt should be.

I would also like to understand what the purpose of things like pDoc-&gt are
(I would appear to be getting a pointer to something).....I get the feeling
that there should be another way of writing this.
HRESULT hr = pDoc->get_body(&pBodyElement);
hr = pBodyElem - >QueryInterface( IID_IHTMLBodyElement,
(void**)&bBody );

Regards
Trevor Keegan
Back to top
Trevor Keegan
Guest





PostPosted: Tue Feb 06, 2007 8:39 am    Post subject: Re: Converting HTML page from TCppWebBrowser into Image Reply with quote



Hello Eduardo,

Thanks....you have just made me feel stupid in the nicest way :-D

Regards
Trevor Keegan
"Eduardo Jauch" <eduardo.jauch (AT) gmail (DOT) com> wrote in message
news:45c7e8a8$1 (AT) newsgroups (DOT) borland.com...
Quote:
Trevor Keegan escreveu:
Hi,

I have been looking at some code from that describes how to convert a
HTML page into an image (http://starkravingfinkle.org/blog/2004/09/).
The problem is before I get started, I see code like:
IHTMLDocument2 * pDoc = ....;
IHTMLELEMENT * pBodyElement = 0
HRESULT hr = pDoc->get_body(&pBodyElement);
if( SUCCEED(hr))
{
IHTMLElement * pBody = 0;
hr = pBodyElem - >QueryInterface( IID_IHTMLBodyElement,
(void**)&bBody );
:
:
}

The problem is I do not know what variables like amp and gt should be.

I would also like to understand what the purpose of things like pDoc-&gt
are (I would appear to be getting a pointer to something).....I get the
feeling that there should be another way of writing this.
HRESULT hr = pDoc->get_body(&pBodyElement);
hr = pBodyElem - >QueryInterface( IID_IHTMLBodyElement,
(void**)&bBody );

Regards
Trevor Keegan

These are NOT variables. Are HTML codes to spécial caracters like "à"

In this case, the correct code is something like this:

IHTMLDocument2 * pDoc = NULL;
IHTMLELEMENT * pBodyElement = NULL;
HRESULT hr = pDoc->get_body( pBodyElement );
if( SUCCEED(hr) )
{
IHTMLElement * pBody = NULL;
hr = pBodyElem->QueryInterface( IID_IHTMLBodyElement, (void**)bBody );
}

You may have problems with the HTML you are viewing...

:)
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Tue Feb 06, 2007 8:39 am    Post subject: Re: Converting HTML page from TCppWebBrowser into Image Reply with quote



"Trevor Keegan" <tkeegan (AT) ealink (DOT) com> wrote in message
news:45c7e3f6 (AT) newsgroups (DOT) borland.com...

Quote:
The problem is I do not know what variables like amp and gt should
be.


They are not variables. They are HTML instructions. '&' is HTML
code for the '&' character, and '>' is the code for the '>'
character. So the code is actually more like the following instead:

IHTMLDocument2 * pDoc = ...;
IHTMLELEMENT * pBodyElement = NULL;
HRESULT hr = pDoc->get_body(&pBodyElement);
if( SUCCEED(hr) )
{
IHTMLElement * pBody = NULL;
hr = pBodyElem->QueryInterface( IID_IHTMLBodyElement,
(void**)&bBody );
...
}


Gambit
Back to top
Eduardo Jauch
Guest





PostPosted: Tue Feb 06, 2007 8:48 am    Post subject: Re: Converting HTML page from TCppWebBrowser into Image Reply with quote

Trevor Keegan escreveu:
Quote:
Hi,

I have been looking at some code from that describes how to convert a HTML
page into an image (http://starkravingfinkle.org/blog/2004/09/). The
problem is before I get started, I see code like:
IHTMLDocument2 * pDoc = ....;
IHTMLELEMENT * pBodyElement = 0
HRESULT hr = pDoc->get_body(&pBodyElement);
if( SUCCEED(hr))
{
IHTMLElement * pBody = 0;
hr = pBodyElem - >QueryInterface( IID_IHTMLBodyElement,
(void**)&bBody );
:
:
}

The problem is I do not know what variables like amp and gt should be.

I would also like to understand what the purpose of things like pDoc-&gt are
(I would appear to be getting a pointer to something).....I get the feeling
that there should be another way of writing this.
HRESULT hr = pDoc->get_body(&pBodyElement);
hr = pBodyElem - >QueryInterface( IID_IHTMLBodyElement,
(void**)&bBody );

Regards
Trevor Keegan



These are NOT variables. Are HTML codes to spécial caracters like "à"

In this case, the correct code is something like this:

IHTMLDocument2 * pDoc = NULL;
IHTMLELEMENT * pBodyElement = NULL;
HRESULT hr = pDoc->get_body( pBodyElement );
if( SUCCEED(hr) )
{
IHTMLElement * pBody = NULL;
hr = pBodyElem->QueryInterface( IID_IHTMLBodyElement, (void**)bBody );
}

You may have problems with the HTML you are viewing...

:)
Back to top
Trevor Keegan
Guest





PostPosted: Tue Feb 06, 2007 9:10 am    Post subject: Re: Converting HTML page from TCppWebBrowser into Image Reply with quote

Hi,

I have managed to working everything out now.....thanks for all the help.

Regards
Trevor Keegan
Back to top
Eduardo Jauch
Guest





PostPosted: Tue Feb 06, 2007 9:10 am    Post subject: Re: Converting HTML page from TCppWebBrowser into Image Reply with quote

Quote:
You may have problems with the HTML you are viewing...

:)


lol


That was not my intention...

Anyway, take a look at the Remy answear.

The code that he posted are the correct...

Because I don't remembered WHAT that codes were exactly ;)

By! Smile
Back to top
Trevor Keegan
Guest





PostPosted: Tue Feb 06, 2007 9:10 am    Post subject: Re: Converting HTML page from TCppWebBrowser into Image Reply with quote

Hello Remy,

Thanks a bunch. :)

I am trying to work out now what code I need to write where it say:

HDC hImageDC = ..... //Could be bitmap or Enhanced MetaFile

Are you able to help me here please.

Regards
Trevor Keegan
Back to top
Hans Galema
Guest





PostPosted: Tue Feb 06, 2007 4:52 pm    Post subject: Re: Converting HTML page from TCppWebBrowser into Image Reply with quote

Trevor Keegan wrote:

Quote:
I have managed to working everything out now.....thanks for all the help.

Nice.

But could not you post the nice clean code ?

Hans.
Back to top
Trevor Keegan
Guest





PostPosted: Wed Feb 07, 2007 5:36 am    Post subject: Re: Converting HTML page from TCppWebBrowser into Image Reply with quote

Hi Hans,

Sure....it is the least that I can do Very Happy Here is is:

void __fastcall TForm1::btnSaveScreenClick(TObject *Sender)
{
TComInterface<IHTMLDocument2> Doc;
CppWebBrowser1->Document->QueryInterface( IID_IHTMLDocument2,
(LPVOID*)&Doc );

if( Doc )
{
IHTMLElement * pBodyElement;
Doc->get_body( &pBodyElement );
if( pBodyElement )
{
IHTMLBodyElement * pBody = 0;
pBodyElement->QueryInterface( IID_IHTMLBodyElement, (void**)&pBody );
if( pBody )
{
//Hide 3D border
IHTMLStyle * pStyle;
pBodyElement->get_style( &pStyle );
if( pStyle )
{
pStyle->put_borderStyle( WideString( "none" ) );
pStyle->Release();
}

//Hide Scroll Bars
pBody->put_scroll( WideString( "no" ) );

//Resize the browser component to the size of the HTML content
IHTMLElement2 * pBodyElement2;
pBody->QueryInterface( IID_IHTMLElement2, (void **)&pBodyElement2 );
if( pBodyElement2 )
{
long iScrollWidth = 0;
long iScrollHeight = 0;
pBodyElement2->get_scrollWidth( &iScrollWidth );
pBodyElement2->get_scrollHeight( &iScrollHeight );

try
{
//Allow the browser window to be resized so that we can get the
whole image
CppWebBrowser1->Align = alNone;

CppWebBrowser1->Width = iScrollWidth;
CppWebBrowser1->Height = iScrollHeight;

pBodyElement2->Release();

IViewObject * pViewObject;
Doc->QueryInterface( IID_IViewObject, ( void ** )&pViewObject );
if( pViewObject )
{
Graphics::TBitmap * Bitmap = new Graphics::TBitmap();
if( Bitmap )
{
RECTL rcSource = {0,0, iScrollWidth, iScrollHeight };
Bitmap->Width = iScrollWidth;
Bitmap->Height = iScrollHeight;
pViewObject->Draw( DVASPECT_CONTENT, 1, NULL, NULL, Handle,
Bitmap->Canvas->Handle, &rcSource, NULL, NULL, 0 );

TJPEGImage * JPEG = new TJPEGImage;
if( JPEG )
{
try
{
JPEG->Assign( Bitmap );
JPEG->SaveToFile( "c:\\Rubbish\\test.jpg" );
}
__finally
{
delete JPEG;
}
}

delete Bitmap;
}

pViewObject->Release();
}
}
__finally
{
//Set the browser back to the original size
CppWebBrowser1->Align = alClient;
}
}
pBody->Release();
}
pBodyElement->Release();
}
Doc->Release();
}
}



Regards
Trevor Keegan
Back to top
Tom
Guest





PostPosted: Wed Feb 07, 2007 9:10 am    Post subject: Re: Converting HTML page from TCppWebBrowser into Image Reply with quote

"Trevor Keegan" <tkeegan (AT) ealink (DOT) com> wrote in message
news:45c9699a (AT) newsgroups (DOT) borland.com...
Quote:
The page that I was printing out was very long and wider than the Browser
size that I had, which is why I needed to remove the Client aligning, to
allow the browser to automatically resize while I captured the screen.
This meant that there was a bit of flicker, but the entire height and
width was captured correctly.

The width was ok. I increased it so that if there was a background image it
gets captured.
The height was about 10-15px too short though.

Quote:
The scroll bars were not captured in the image here at all.

Are you still using IE6 by chance?

I found some source code for from an opensource project that's quite similar
to yours.
However, it also compares rootwidth,height and uses that if bigger. I think
that may solve
my dimension issues. I need to take a look at the code again in regards to
the scrollbars
as they aren't even turning them off but they don't show up in the images.

Regards,

Tom
Back to top
Tom
Guest





PostPosted: Wed Feb 07, 2007 9:10 am    Post subject: Re: Converting HTML page from TCppWebBrowser into Image Reply with quote

First of all thanks for this code. However, I'm having
a couple of issues with it. One of which is pretty much
solved.

1. The Width and Height were too small. I simply
increased the Browser width and height a bit beyond
what the scroll width/height are. That part seems ok
now.

2. The scroll bars are still there. Using
http://movies.yahoo.com as an example and saving
that picture, I still have the scrollbars on the right.
Are there still there for you? I figure I can trim
the picture down before saving it, but was hoping
for a cleaner solution.

Regards,

Tom
Back to top
Trevor Keegan
Guest





PostPosted: Wed Feb 07, 2007 9:10 am    Post subject: Re: Converting HTML page from TCppWebBrowser into Image Reply with quote

Hi Tom,

Quote:
1. The Width and Height were too small. I simply
increased the Browser width and height a bit beyond
what the scroll width/height are. That part seems ok
now.
The page that I was printing out was very long and wider than the Browser

size that I had, which is why I needed to remove the Client aligning, to
allow the browser to automatically resize while I captured the screen. This
meant that there was a bit of flicker, but the entire height and width was
captured correctly.

Quote:
2. The scroll bars are still there. Using
http://movies.yahoo.com as an example and saving
that picture, I still have the scrollbars on the right.
Are there still there for you? I figure I can trim
the picture down before saving it, but was hoping
for a cleaner solution.
The scroll bars were not captured in the image here at all.


Regards
Trevor Keegan
Back to top
Trevor Keegan
Guest





PostPosted: Wed Feb 07, 2007 9:10 am    Post subject: Re: Converting HTML page from TCppWebBrowser into Image Reply with quote

Hello Tom,

Quote:
Are you still using IE6 by chance?
Yes I am.


Quote:
I found some source code for from an opensource project that's quite
similar to yours.
However, it also compares rootwidth,height and uses that if bigger. I
think that may solve
my dimension issues. I need to take a look at the code again in regards to
the scrollbars
as they aren't even turning them off but they don't show up in the images.
I would be interested to see the code. FYI I had found another delphi code

for this http://www.delphifaq.com/faq/f408.shtml

Regards
Trevor Keegan
Back to top
Hans Galema
Guest





PostPosted: Wed Feb 07, 2007 9:10 am    Post subject: Re: Converting HTML page from TCppWebBrowser into Image Reply with quote

Trevor Keegan wrote:

Quote:
Sure....it is the least that I can do Very Happy Here is is:

Thank you. At the moment I do not need it. Will add it to
the collection and follow this thread further.

Hans.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Internet Web) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.