Question about TPrintPreview

Please post bug reports, feature requests, or any question regarding the DELPHI AREA projects here.

Question about TPrintPreview

Postby m_b » June 23rd, 2004, 10:35 am

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
m_b
Active Member
Active Member
 
Posts: 18
Joined: June 23rd, 2004, 10:19 am

Would like to use TPrintPreview with HTML

Postby XML » June 24th, 2004, 1:33 pm

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?
XML
Member
Member
 
Posts: 1
Joined: June 24th, 2004, 1:29 pm

Re: Would like to use TPrintPreview with HTML

Postby Johnny_Bit » June 24th, 2004, 9:21 pm

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...
Johnny_Bit
VIP Member
VIP Member
 
Posts: 455
Joined: June 15th, 2003, 9:56 am

Postby m_b » June 24th, 2004, 10:49 pm

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
m_b
Active Member
Active Member
 
Posts: 18
Joined: June 23rd, 2004, 10:19 am

Postby Johnny_Bit » June 25th, 2004, 4:28 am

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
Johnny_Bit
VIP Member
VIP Member
 
Posts: 455
Joined: June 15th, 2003, 9:56 am

Postby m_b » June 25th, 2004, 9:33 am

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
m_b
Active Member
Active Member
 
Posts: 18
Joined: June 23rd, 2004, 10:19 am

Postby Kambiz » June 25th, 2004, 10:11 am

Interesting codes here!
Thanks everybody!
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Postby m_b » June 26th, 2004, 10:24 am

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

Cheers!

m_b
m_b
Active Member
Active Member
 
Posts: 18
Joined: June 23rd, 2004, 10:19 am

Postby Kambiz » June 26th, 2004, 11:55 am

I'm sorry, but there is not enough reason to improve the component by adding support for SynEdit and HTML.
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Postby m_b » June 27th, 2004, 11:30 am

:cry: :cry: :cry: Why not??? It would be great... Please...[/b]
m_b
Active Member
Active Member
 
Posts: 18
Joined: June 23rd, 2004, 10:19 am

Postby Kambiz » June 27th, 2004, 10:01 pm

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
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm

Postby m_b » June 28th, 2004, 8:17 am

Well, thanks anyway...

m_b
m_b
Active Member
Active Member
 
Posts: 18
Joined: June 23rd, 2004, 10:19 am

Can't Compile

Postby PomPom » July 5th, 2004, 2:14 pm

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...
PomPom
Member
Member
 
Posts: 2
Joined: July 5th, 2004, 2:07 pm

Postby Johnny_Bit » July 5th, 2004, 2:48 pm

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.
Johnny_Bit
VIP Member
VIP Member
 
Posts: 455
Joined: June 15th, 2003, 9:56 am

Postby m_b » July 5th, 2004, 6:40 pm

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
m_b
Active Member
Active Member
 
Posts: 18
Joined: June 23rd, 2004, 10:19 am

Next

Return to DELPHI AREA Projects

Who is online

Users browsing this forum: No registered users and 45 guests

cron