Page 1 of 2

Question about TPrintPreview

PostPosted: June 23rd, 2004, 10:35 am
by m_b
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

Would like to use TPrintPreview with HTML

PostPosted: June 24th, 2004, 1:33 pm
by XML
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?

Re: Would like to use TPrintPreview with HTML

PostPosted: June 24th, 2004, 9:21 pm
by Johnny_Bit
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...

PostPosted: June 24th, 2004, 10:49 pm
by m_b
Sorry I didn't reply earlier, I have almost no time to breathe.
:cry:
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

PostPosted: June 25th, 2004, 4:28 am
by Johnny_Bit
1st way:

use TSynExporterRTF as follows:

Code: Select all
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:

Code: Select all
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

PostPosted: June 25th, 2004, 9:33 am
by m_b
OK, here's something for XML first:

Code: Select all
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

PostPosted: June 25th, 2004, 10:11 am
by Kambiz
Interesting codes here!
Thanks everybody!

PostPosted: June 26th, 2004, 10:24 am
by m_b
Does that mean there's gonna be a new version supporting these features. I sure hope so, can't wait... :D

Cheers!

m_b

PostPosted: June 26th, 2004, 11:55 am
by Kambiz
I'm sorry, but there is not enough reason to improve the component by adding support for SynEdit and HTML.

PostPosted: June 27th, 2004, 11:30 am
by m_b
:cry: :cry: :cry: Why not??? It would be great... Please...[/b]

PostPosted: June 27th, 2004, 10:01 pm
by Kambiz
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

PostPosted: June 28th, 2004, 8:17 am
by m_b
Well, thanks anyway...

m_b

Can't Compile

PostPosted: July 5th, 2004, 2:14 pm
by PomPom
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...

PostPosted: July 5th, 2004, 2:48 pm
by Johnny_Bit
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.

PostPosted: July 5th, 2004, 6:40 pm
by m_b
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... :D

Cheers

Marko