ScaleRichview Document with Headers and Footers to PDF

ScaleRichView support and discussion (TRichView add-on for WYSIWYG editing)
Post Reply
rron
Posts: 5
Joined: Tue Mar 25, 2008 12:14 am
Contact:

ScaleRichview Document with Headers and Footers to PDF

Post 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.
Attachments
DocumentWithHeaderFooter.rvf
(98.54 KiB) Downloaded 4179 times
Sergey Tkachenko
Site Admin
Posts: 17602
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: ScaleRichview Document with Headers and Footers to PDF

Post 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.
rron
Posts: 5
Joined: Tue Mar 25, 2008 12:14 am
Contact:

Re: ScaleRichview Document with Headers and Footers to PDF

Post 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;
Post Reply