trichview.support
Re: RichAction and TPDFDocument componant |
Author |
Message |
Adam Allen |
Posted: 02/19/2005 19:14:28 Hello Sergey, No, not fixed yet, same error; here is the complete code, your code working without the PDF with getting error with PDF component Thanks procedure TForm3.Button4Click(Sender: TObject); var i, LeftMargin, TopMargin, RightMargin, BottomMargin, DocWidth, DocHeight: Integer; pt: TPoint; Stream: TMemoryStream; const MinDocSize = 50; begin LeftMargin := GetMargin(txtLeft); TopMargin := GetMargin(txtTop); RightMargin := GetMargin(txtRight); BottomMargin := GetMargin(txtBottom); pdf.Resolution := Screen.PixelsPerInch; pdf.FileName := 'c:\test.pdf'; pdf.BeginDoc; // pdf.Page[0].Size := GetPageSize; // pdf.Page[0].Orientation := GetPageOrientation; DocWidth := pdf.Page[0].Width - (LeftMargin+RightMargin); DocHeight := pdf.Page[0].Height - (TopMargin+BottomMargin); if (DocWidth<MinDocSize) then begin ShowError('Horizontal margins are too large'); txtLeft.SetFocus; pdf.Abort; exit; end; if (DocHeight<MinDocSize) then begin ShowError('Vertical margins are too large'); txtTop.SetFocus; pdf.Abort; exit; end; Screen.Cursor := crHourGlass; try ShowText('Formatting...', True); Stream := TMemoryStream.Create; RichViewEdit1.SaveRVFToStream(Stream,False); Stream.Position := 0; rvrh.RichView.Style := RVStyle1; rvrh.RichView.RVFTextStylesReadMode := rvf_sIgnore; rvrh.RichView.RVFParaStylesReadMode := rvf_sIgnore; if rvoTagsArePChars in RichViewEdit1.Options then rvrh.RichView.Options := rvrh.RichView.Options+[rvoTagsArePChars]; rvrh.RichView.Clear; rvrh.RichView.LoadRVFFromStream(Stream); Stream.Free; // showmessage(inttostr(rvrh.RichView.ItemCount)); rvrh.Init(pdf.Canvas, DocWidth); //here is the problem can not assign it to pdf.Canvas while rvrh.FormatNextPage(DocHeight) do; for i := 0 to rvrh.PagesCount-1 do begin ShowText(Format('Collecting PDF pages (%d of %d)... ', [i, rvrh.PagesCount]), False); if i>0 then begin pdf.NewPage; pdf.Page[i].Size := pdf.Page[0].Size; pdf.Page[i].Orientation := pdf.Page[0].Orientation; end; SetViewportOrgEx(pdf.Canvas.Handle, LeftMargin, TopMargin, @pt); rvrh.DrawPage(i+1, pdf.Canvas, False, DocHeight); SetViewportOrgEx(pdf.Canvas.Handle, pt.x, pt.y, nil); end; ShowText('Writing PDF file...', True); pdf.EndDoc; finally // Stream.Free; // application.Terminate; end; end; "Sergey Tkachenko" <[email protected]> wrote in message news:[email protected]... > Problems in this code: > > 1) Since rvrh.RichView is empty before calling DeleteUnusedStyles, this > call > deletes all styles but the 0-th. > But these styles are used also by RichViewEdit1, so the most likely the > document is damaged > 2) rvrh.PagesCount>0 only if the document is formatted (rvrh.Init and > rvrh.FormatNextPage are called). > You can check if the document is loaded checking rvrh.RichView.ItemCount. > In my tests, the document is loaded. > 2) rvrh.Ready should always be False (this property works properly only in > RVPrint), so the code inside IF should never be called. But when I removed > this condition (also, I removed the lines > pdf.Page[0].Size := GetPageSize; > pdf.Page[0].Orientation := GetPageOrientation) > the document was successfully converted to PDF. > > The best way to copy the document in the reporthelper: > > Stream: TMemoryStream; > > Stream := TMemoryStream.Create; > RichViewEdit1.SaveRVFToStream(Stream,False); > Stream.Position := 0; > rvrh.RichView.Style := RVStyle1; > rvrh.RichView.RVFTextStylesReadMode := rvf_sIgnore; > rvrh.RichView.RVFParaStylesReadMode := rvf_sIgnore; > if rvoTagsArePChars in RichViewEdit1.Options then > rvrh.RichView.Options := rvrh.RichView.Options+[rvoTagsArePChars]; > rvrh.RichView.Clear; > rvrh.RichView.LoadRVFFromStream(Stream); > Stream.Free; > showmessage(inttostr(rvrh.RichView.ItemCount)); > > And remove > if rvrh.Ready then > > |
Powered by ABC Amber Outlook Express Converter