🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.internet.web
14 messages
14 total messages Started by Trevor Keegan Tue, 06 Feb 2007 02:13
Converting HTML page from TCppWebBrowser into Image
#435
Author: Trevor Keegan
Date: Tue, 06 Feb 2007 02:13
28 lines
1834 bytes
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 
Re: Converting HTML page from TCppWebBrowser into Image
#241
Author: Trevor Keegan
Date: Tue, 06 Feb 2007 02:39
54 lines
2808 bytes
Hello Eduardo,

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

Regards
Trevor Keegan
"Eduardo Jauch" <eduardo.jauch@gmail.com> wrote in message 
news:45c7e8a8$1@newsgroups.borland.com...
> 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-&gt;get_body(&amp;pBodyElement);
>> if( SUCCEED(hr))
>> {
>>   IHTMLElement * pBody = 0;
>>   hr = pBodyElem - &gt;QueryInterface( IID_IHTMLBodyElement, 
>> (void**)&amp;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-&gt;get_body(&amp;pBodyElement);
>>   hr = pBodyElem - &gt;QueryInterface( IID_IHTMLBodyElement, 
>> (void**)&amp;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...
>
> :) 
Re: Converting HTML page from TCppWebBrowser into Image
#240
Author: Remy Lebeau (TeamB)
Date: Tue, 06 Feb 2007 02:39
24 lines
1632 bytes
"Trevor Keegan" <tkeegan@ealink.com> wrote in message
news:45c7e3f6@newsgroups.borland.com...

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

They are not variables.  They are HTML instructions.  '&amp;' is HTML
code for the '&' character, and '&gt;' 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
Re: Converting HTML page from TCppWebBrowser into Image
#239
Author: Eduardo Jauch
Date: Tue, 06 Feb 2007 02:48
48 lines
2407 bytes
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-&gt;get_body(&amp;pBodyElement);
> if( SUCCEED(hr))
> {
>   IHTMLElement * pBody = 0;
>   hr = pBodyElem - &gt;QueryInterface( IID_IHTMLBodyElement, 
> (void**)&amp;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-&gt;get_body(&amp;pBodyElement);
>   hr = pBodyElem - &gt;QueryInterface( IID_IHTMLBodyElement, 
> (void**)&amp;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...

:)	
Re: Converting HTML page from TCppWebBrowser into Image
#242
Author: Eduardo Jauch
Date: Tue, 06 Feb 2007 03:19
16 lines
1304 bytes
>> 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! :)
Re: Converting HTML page from TCppWebBrowser into Image
#243
Author: Trevor Keegan
Date: Tue, 06 Feb 2007 03:26
12 lines
1325 bytes
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 
Re: Converting HTML page from TCppWebBrowser into Image
#244
Author: Trevor Keegan
Date: Tue, 06 Feb 2007 04:40
6 lines
1170 bytes
Hi,

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

Regards
Trevor Keegan 
Re: Converting HTML page from TCppWebBrowser into Image
#246
Author: Hans Galema
Date: Tue, 06 Feb 2007 10:52
9 lines
1203 bytes
Trevor Keegan wrote:

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

Nice.

But could not you post the nice clean code ?

Hans.
Re: Converting HTML page from TCppWebBrowser into Image
#255
Author: Trevor Keegan
Date: Tue, 06 Feb 2007 23:36
104 lines
4127 bytes
Hi Hans,

Sure....it is the least that I can do :-D 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 
Re: Converting HTML page from TCppWebBrowser into Image
#256
Author: Tom
Date: Wed, 07 Feb 2007 03:32
19 lines
1764 bytes
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 
Re: Converting HTML page from TCppWebBrowser into Image
#257
Author: Trevor Keegan
Date: Wed, 07 Feb 2007 05:54
22 lines
2152 bytes
Hi Tom,

> 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.

> 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 
Re: Converting HTML page from TCppWebBrowser into Image
#258
Author: Tom
Date: Wed, 07 Feb 2007 07:21
28 lines
2219 bytes
"Trevor Keegan" <tkeegan@ealink.com> wrote in message 
news:45c9699a@newsgroups.borland.com...
> 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.

> 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 
Re: Converting HTML page from TCppWebBrowser into Image
#259
Author: Trevor Keegan
Date: Wed, 07 Feb 2007 07:53
17 lines
1884 bytes
Hello Tom,

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

> 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 
Re: Converting HTML page from TCppWebBrowser into Image
#260
Author: Hans Galema
Date: Wed, 07 Feb 2007 08:12
8 lines
1331 bytes
Trevor Keegan wrote:

> Sure....it is the least that I can do :-D 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.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads