#1: Question about TPrintPreview Author: m_b, Posted: 23/06/04 10:35 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 . 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
#2: Would like to use TPrintPreview with HTML Author: XML, Posted: 24/06/04 13:33 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?
#3: Re: Would like to use TPrintPreview with HTML Author: Johnny_Bit, Posted: 24/06/04 21:21
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...
#4: Author: m_b, Posted: 24/06/04 22:49 Sorry I didn't reply earlier, I have almost no time to breathe.
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
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
#6: Author: m_b, Posted: 25/06/04 09:33 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,
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.
#8: Author: m_b, Posted: 26/06/04 10:24 Does that mean there's gonna be a new version supporting these features. I sure hope so, can't wait...
Cheers!
m_b
#9: Author: Kambiz, Location: Tehran, IranPosted: 26/06/04 11:55 I'm sorry, but there is not enough reason to improve the component by adding support for SynEdit and HTML.
#10: Author: m_b, Posted: 27/06/04 11:30 Why not??? It would be great... Please...[/b]
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.
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).
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...
#14: Author: Johnny_Bit, Posted: 05/07/04 14:48 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.
#15: Author: m_b, Posted: 05/07/04 18:40 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;