DELPHI AREA
MESSAGE BOARD
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   FavoritesFavorites   Watched TopicsWatched Topics     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Question about TPrintPreview
Goto page 1, 2  Next
 
Post new topic   Reply to topic   printer-friendly view    DELPHI AREA Forum Index -> DELPHI AREA's Products
View previous topic :: View next topic  
Author Message
m_b
Member


Joined: 23 Jun 2004
Posts: 18

PostPosted: 23/06/04 10:35    Post subject: Question about TPrintPreview Reply with quote

Hi, I'm creating an HTML WYSIWYG and code editor which uses Microsoft MSHTML. Now, I need a print preview both for the WYSIWYG part and the code part, but MSIE and SynEdit PrintPreviews are just UGLY Sad . I like everything about your component, but I was disapointed to see that it can't work with html pages nor with SynEdit. So I would appreciate it very much if you added MSHTML and SynEdit support to it.
If you decide to help me and don't know MSHTML very well (beleieve me, it's very hard to work with) I can post a function which gets the whole rendered html page bitmap, or you can take a look at the msdn articles on Print Templates in IE (actual article is "Beyond PrintPreview"). Regarding SynEdit - it's a free delphi component, similar to RichEdit, with full sourcecode and it's own PrintPreview - so you can get all the info you need from there.

Thanks!

m_b
Back to top
View user's profile Send private message
XML
Member


Joined: 24 Jun 2004
Posts: 1

PostPosted: 24/06/04 13:33    Post subject: Would like to use TPrintPreview with HTML Reply with quote

Hi m_b,

also have problems with print preview of HTML pages.

Pleas could you post your solution to get the rendered page of a HTML code?

Thankx
XML

SynEdit? Where to find?
Back to top
View user's profile Send private message
Johnny_Bit
Moderator


Joined: 15 Jun 2003
Posts: 274

PostPosted: 24/06/04 21:21    Post subject: Re: Would like to use TPrintPreview with HTML Reply with quote

XML wrote:
SynEdit? Where to find?


http://synedit.sourceforge.net/

Besides: syn edit makes print preview as metafiles, so you can use syn edit's metafiles with printpreview, or render it by yourself.. just follow rule: "Analyze & interprett"

print preview for HTMLs? good.. if i could just use gecko i would maqke it but with that sh**t* activeX control...
Back to top
View user's profile Send private message Send e-mail Visit poster's website
m_b
Member


Joined: 23 Jun 2004
Posts: 18

PostPosted: 24/06/04 22:49    Post subject: Reply with quote

Sorry I didn't reply earlier, I have almost no time to breathe.
Crying or Very sad
Now:

XML - I'll post the code for you tomorow, I need to get some sleep now - it's 12:50 PM here...

Johnny_Bit - Can you show me exactly how to do this with SynEdit? Thanks

See ya tomorrw...

m_b
Back to top
View user's profile Send private message
Johnny_Bit
Moderator


Joined: 15 Jun 2003
Posts: 274

PostPosted: 25/06/04 04:28    Post subject: Reply with quote

1st way:

use TSynExporterRTF as follows:

procedure TForm1.Button1Click(Sender: TObject);
var
sRTF: TMemoryStream;
rePrint: TCustomRichEdit;
rRect: TRect;
begin
sRTF:=TMemoryStream.Create;
SynExporterRTF1.SaveToStream(sRTF);
rePrint:=TRichEdit.Create(nil);
//here you set rich edit properties
rePrint.Lines.LoadFromStream(sRTF);
sRTF.Free;
PrintPreview1.GetRichTextRect(rRect, rePrint, nil);
PrintPreview1.PaintRichText(rRect, rePrint, 0, nil);
rePrint.Free
end;

2nd way:

procedure TForm1.Button2Click(Sender: TObject);
var
I: Integer;
begin
PrintPreview1.BeginDoc;
for I:=0 to SynEditPrint1.PageCount-1 do
begin
PrintPreview1.NewPage;
SynEditPrint1.PrintToCanvas(PrintPreview1.Canvas, I);
end;
PrintPreview1.EndDoc;
end;

I'm sure, that there is 3rd way, but this 2 presented is enought
Back to top
View user's profile Send private message Send e-mail Visit poster's website
m_b
Member


Joined: 23 Jun 2004
Posts: 18

PostPosted: 25/06/04 09:33    Post subject: Reply with quote

OK, here's something for XML first:

procedure GetPageBMP(FileName:String;srcHeight: Integer; srcWidth: Integer);
var
sourceDrawRect : TRect;
sourceBitmap: TBitmap;
viewObject: IViewObject;
begin
sourceBitmap := TBitmap.Create ;
Application.ProcessMessages;
WebBrowser1.Navigate(FileName);
while WebBrowser1.ReadyState < 4 do
Application.ProcessMessages;
Sleep(100);
while WebBrowser1.Busy do
Application.ProcessMessages;
WebBrowser1.Width:=srcWidth + 18;
WebBrowser1.Height:=srcHeight + 16;
sourceDrawRect := Rect (-2, -2, srcWidth, srcHeight);
sourceBitmap.Width := srcWidth - 21;
sourceBitmap.Height := srcHeight - 14;
viewObject := Webbrowser1.ControlInterface as IViewObject;
if viewObject = nil then
exit;
OleCheck(viewObject.Draw(DVASPECT_CONTENT, 1, nil, nil,

Self.Handle,sourceBitmap.Canvas.Handle, @sourceDrawRect, nil, nil, 0));
sourcebitmap.SaveToFile('c:\pagebmp.bmp');
end;

This procedure only gets the part of the page you specify, not the whole page. And I'm still trying to find a way to get the width and height of the whole page so I can resize the WB approprietly, but it seems that there's no way. Microsoft speaks of print templates - but doesn't say exactly how to use them.

And to you Jonny_bit > Thanks alot!

Cheers!

m_b
Back to top
View user's profile Send private message
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 1044
Location: Tehran, Iran

PostPosted: 25/06/04 10:11    Post subject: Reply with quote

Interesting codes here!
Thanks everybody!
Back to top
View user's profile Send private message Send e-mail Visit poster's website
m_b
Member


Joined: 23 Jun 2004
Posts: 18

PostPosted: 26/06/04 10:24    Post subject: Reply with quote

Does that mean there's gonna be a new version supporting these features. I sure hope so, can't wait... Very Happy

Cheers!

m_b
Back to top
View user's profile Send private message
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 1044
Location: Tehran, Iran

PostPosted: 26/06/04 11:55    Post subject: Reply with quote

I'm sorry, but there is not enough reason to improve the component by adding support for SynEdit and HTML.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
m_b
Member


Joined: 23 Jun 2004
Posts: 18

PostPosted: 27/06/04 11:30    Post subject: Reply with quote

Crying or Very sad Crying or Very sad Crying or Very sad Why not??? It would be great... Please...[/b]
Back to top
View user's profile Send private message
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 1044
Location: Tehran, Iran

PostPosted: 27/06/04 22:01    Post subject: Reply with quote

I've already told why!

How many people are going to use PrintPreview in conjunction with either SynEdit or WebBrowser? How many people don't use it for these purposes? A small component is suitble for more people.

Jhonny_Bit demonstrated how easily the text in SynEdit can be printed by PrintPrwview. I believe its better the programmer prints the text in the way she/he has more control over it.

What about the WebBrowser? Well, when you do low level tasks with WebBrowser, you have to be aware that with every new service pack you may need to review your code, otherwise you'll get some AV exceptions. This has happened to me several times and I'm not going to make a new nightmare in my life. Wink

Anyway, PrintPreview is open source. So, you can modify, and even distribute the modified version under your own name (of course as freeware and including the original copyright notice).

Cheers,
Kambiz
Back to top
View user's profile Send private message Send e-mail Visit poster's website
m_b
Member


Joined: 23 Jun 2004
Posts: 18

PostPosted: 28/06/04 08:17    Post subject: Reply with quote

Well, thanks anyway...

m_b
Back to top
View user's profile Send private message
PomPom
Member


Joined: 05 Jul 2004
Posts: 2

PostPosted: 05/07/04 14:14    Post subject: Can't Compile Reply with quote

Hi !

I'm totally new in Delphi & gettin' used to it!
Got version 7. I wonder why I can't compile this TPrintPreview..
It says I need a dcu file Preview.dcu.
It doesn't recognize the declaration of Preview in "uses" section.

Thank U to help me finding this file or maybe a component I need to install...
Back to top
View user's profile Send private message
Johnny_Bit
Moderator


Joined: 15 Jun 2003
Posts: 274

PostPosted: 05/07/04 14:48    Post subject: Reply with quote

Delphi Newbie? Just go to Tools->Envoroniment Options->Library Path and add dir where you put print preview. now open preview.pas goto component->install component click on instal, then save all and that's it.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
m_b
Member


Joined: 23 Jun 2004
Posts: 18

PostPosted: 05/07/04 18:40    Post subject: Reply with quote

Hi, I just found out how to get the width and height of the full HTML page. So, here it is:

height := ((WebBrowser1.document as IHTMLDocument2).body as IHTMLElement2).scrollHeight;

Width depends on paper size - it wraps around the web browser, so:

width := ((WebBrowser1.document as IHTMLDocument2).body as IHTMLElement2).scrollWidth;

Just thought someone can find this useful... Very Happy

Cheers

Marko
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    DELPHI AREA Forum Index -> DELPHI AREA's Products All times are GMT
Goto page 1, 2  Next
Page 1 of 2

Add to favorites

 
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
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group