Page 1 of 1
ScaleRichview Document with Headers and Footers to PDF
Posted: Sat Jan 25, 2020 10:34 pm
by rron
I am trying to export a document to PDF using SynPDF. I am using the RV2PDF demo with RichView 18 and ScaleRichView 9 as an example. The issue is that the header and footer height is not correct in the PDF so I get more pages than my original document.
I have included a document with this issue.
Re: ScaleRichview Document with Headers and Footers to PDF
Posted: Sun Jan 26, 2020 4:10 pm
by Sergey Tkachenko
What code exactly do you use to create PDF?
You should not use code that includes TRVPrint or TRVReportHelper components for ScaleRichView.
The code must use TSRichViewEdit.DrawPage to draw pages in PDF.
Re: ScaleRichview Document with Headers and Footers to PDF
Posted: Wed Jan 29, 2020 12:29 am
by rron
I was indeed using TRVPrint and TRVReportHelper. Looking into into using Drawpage and some examples, I came up with this using llPDFLib :
Code: Select all
function TRichViewMerge.ExportPdfToFile(PDFFileName: String): Boolean;
Var PDFDocument: TPDFDocument;
PageSize: TSize;
i: Integer;
Const PixelPerInch = 96;
begin
PDFDocument := TPDFDocument.Create(Nil);
PDFDocument.FileName := PDFFileName;
Try
PageSize.cx := FScaleRichViewEdit.RichViewEdit.Style.RVUnitsToStandardPixels(FScaleRichViewEdit.RichViewEdit.DocParameters.PageWidth, FScaleRichViewEdit.RichViewEdit.DocParameters.Units);
PageSize.cy := FScaleRichViewEdit.RichViewEdit.Style.RVUnitsToStandardPixels(FScaleRichViewEdit.RichViewEdit.DocParameters.PageHeight, FScaleRichViewEdit.RichViewEdit.DocParameters.Units);
PDFDocument.Resolution := PixelPerInch;
PDFDocument.BeginDoc;
{PDF page size is measured in pixels, with DPI = PDFPixelsPerInch}
PDFDocument.Page[0].Width := MulDiv(PageSize.cx, PixelPerInch, PixelPerInch);
PDFDocument.Page[0].Height := MulDiv(PageSize.cy, PixelPerInch, PixelPerInch);
For i := 0 To FScaleRichViewEdit.PageCount - 1 Do
Begin
if i > 0 then
begin
PDFDocument.NewPage;
PDFDocument.Page[i].Width := PDFDocument.Page[0].Width;
PDFDocument.Page[i].Height := PDFDocument.Page[0].Height;
end;
PDFDocument.Canvas.Font.PixelsPerInch := PixelPerInch;
FScaleRichViewEdit.DrawPage(i + 1, FScaleRichViewEdit.PageWidth100Pix, FScaleRichViewEdit.PageHeight100Pix, 0, 0, PDFDocument.Canvas, False, False, False, False, False);
End;
PDFDocument.EndDoc;
Finally
PDFDocument.Free;
End;
end;