trichview.support
Re: screen <-> printer |
Author |
Message |
Frank Kroeger |
Posted: 07/23/2003 0:01:41 Hi Sergey, I tried your suggestion but no luck. As a test I tried to draw a page on the prncanvas and then copy this canvas to the printer.canvas. I figure this should then print out the generated page. But this does not word. Can you tell me what I am doing wrong here? Here is the code I used: procedure TForm1.test1Click(Sender: TObject); var PrnCanvas : TCanvas; PrnDC : HDC; printerdpi, docleft, doctop, docwidth, docheight : integer; destrect : TRect; begin PrnCanvas := TCanvas.Create; PrnDC := RV_GetPrinterDC; PrnCanvas.Handle := PrnDC; PrnCanvas.Font.PixelsPerInch := GetDeviceCaps(PrnDC, LOGPIXELSY); printerdpi := GetDeviceCaps(PrnCanvas.Handle,lOGPIXELSX); Try docleft := 0; doctop := 0; docwidth := mmToPix(167,printerdpi); docHeight := mmToPix(150,printerdpi); rvh.clear; If rvh.RichView.LoadRVF('d:\rabea.rvf') then begin rvh.RichView.LeftMargin := 0; rvh.RichView.TopMargin := 0; rvh.RichView.RightMargin := 0; rvh.RichView.BottomMargin := 0; rvh.Init(prncanvas,docwidth); While rvh.FormatNextPage(docHeight) do; rvh.DrawPageAt(docleft,doctop,1,PrnCanvas,false,docHeight); destrect.Left := 0; destrect.Top := 0; destrect.Right := getdevicecaps(prncanvas.Handle,horzres); destrect.Bottom := getdevicecaps(prncanvas.Handle,vertres); printer.BeginDoc; printer.canvas.CopyMode := cmSrcCopy; printer.canvas.CopyRect(destrect,prncanvas,destrect); printer.enddoc; end; finally PrnCanvas.Handle := 0; DeleteDC(PrnDC); PrnCanvas.Free; end; end; I created and used the prncanvas as you suggested. After drawing I simply copy the canvas to the printer.canvas. If I am not mistaken this should also print the generated page but all I get is a blank page. The other method you suggested (using a dummy page and TRVPrintPreview's OnPagePrepaint event) I believe is in my case not so easy to use. I print several RVF-documents on one page but do not know beforehand how many pages I need. This is calculated on the fly. To use TRVPrintPreview I would need to know the number of pages before I start the preview. Tia, Frank Kroeger "Sergey Tkachenko" <[email protected]> wrote: >Hi, > >If you want to create the same image on printer and paper, you need: >1) Format reporthelper in printer resolution. You need to create >printer-compatible canvas and use it for reporthelper.Init() > >Creating: >var > PrnCanvas: TCanvas; > PrnDC: HDC; > > PrnCanvas := TCanvas.Create; > PrnDC := RV_GetPrinterDC; // from PtblRV unit > PrnCanvas.Handle := PrnDC; > PrnCanvas.Font.PixelsPerInch := GetDeviceCaps(PrnDC, LOGPIXELSY); > >Destroying (when all drawing is finished) > > PrnCanvas.Handle := 0; > DeleteDC(PrnDC); > PrnCanvas.Free; > >2) When printing, use rvhelper.DrawPageAt(... Printer.Canvas ...), as I >guess you currently do >3) When drawing preview, you need to scale image. >There is a simple method for previewing: using TRVPrintPreview showing some >fake (empty) document. You can draw preview in OnPagePrepaint event. >Example: http://www.trichview.com/support/files/preview.zip > > > >> >> Hi, >> >> I use TRVReportHelper to print multiple records of a report on one or more >> pages. >> TRVReportHelper draws the pages onto the printercanvas and as a preview to >> a TImage as in one of your demos. Of course it would be nice if the >preview >> would look like the print. But this is not the case. >> >> If I e.g. draw on the printercanvas in a given region of lets say 15 cm >the >> printer fits approx. 30 lines of text into this area. If I do the same >with >> the TImage it only fits 27-28 lines of text in the same region of 15 cm. >> >> This can leed to different number of pages send to the printer, and >created >> on the TImage as a preview. This can be pretty annoying. >> >> I calculate the width and height of my area in pixel with: >> >> function mmToPixel(mm:extended;dpi:integer):integer; >> begin >> Result := round( (mm / 25.4) * dpi ); >> end; >> >> Where for the TImage dpi = GetDeviceCaps(TImage.Canvas.Handle, LOGPIXELSX) >> and for the printer dpi = GetDeviceCaps(printer.Handle, LOGPIXELSX). >> >> I assume it might have something to do with the difference in resolution >> ( 96 dpi <-> 600 dpi ) but I'm not sure. >> >> Furthermore in the TImage more characters can be fit in one line. >> >> To make it short: A page drawn to a printercanvas does not look like a >page >> drawn to an imagecanvas. >> >> Am I missing something or am I making something wrong? >> >> Perhaps you could enlighten me. >> >> Tia >> >> Frank Kroeger > > |
Powered by ABC Amber Outlook Express Converter