convert metafile to pdf using freereport

edited 10:01AM in FreeReport
Hi,

could someone help me?

I'm almost getting a report convert to pdf but there is inconsistency with the size of the generated PDF page.


freerep-pdf.JPG


routine figure 1:

Here I subtract 250 units to display all records. (250 were based on trial and error)

frReport1.EMFPages.Draw(i, EMFCanvas,
Rect(0, 0, PageInfo.PrnInfo.PgW, PageInfo.PrnInfo.PgH-250)); //here


routine figure 2:

this statement were shown only 80% of records

frReport1.EMFPages.Draw(i, EMFCanvas,
Rect(0, 0, PageInfo.PrnInfo.PgW, PageInfo.PrnInfo.PgH));


area of 3 images show an area that is still unfilled, resulting in incorrect page report with about the report displayed in the preview freepreport.


my routine:

procedure TForm1.SpeedButton6Click(Sender: TObject);
var i:integer;
EMF: TMetafile;
EMFCanvas: TMetafileCanvas;
PageInfo: PfrPageInfo;
vpdf : TPdfDocumentGDI;
begin

frReport1.LoadFromFile('C:\Program Files (x86)\Delphi7SE\Testes\FreeReport\Simples\TESTE.frf');
frReport1.ShowProgress:=false;
frReport1.PrepareReport;

vpdf := TPdfDocumentGDI.Create;
vpdf.GeneratePDF15File:=true;
vpdf.CompressionMethod := cmNone;

for i:=0 to frReport1.EMFPages.Count-1 do begin
PageInfo :=frReport1.EMFPages;

EMF := TMetafile.Create;

EMF.Width := PageInfo.pgWidth;
EMF.Height := PageInfo.pgHeight;

EMFCanvas := TMetafileCanvas.Create(EMF, 0);
PageInfo.Visible := True;

frReport1.EMFPages.Draw(i, EMFCanvas,
Rect(0, 0, PageInfo.PrnInfo.PgW, PageInfo.PrnInfo.PgH));

{ frReport1.EMFPages.Draw(i, EMFCanvas,
Rect(0, 0, PageInfo.PrnInfo.PgW, PageInfo.PrnInfo.PgH - 250 ));
}

vpdf.AddPage;

EMFCanvas.Free;

vpdf.VCLCanvas.Draw(0,0,EMF);

EMF.Free;
end;

vpdf.SaveToFile('C:\Users\BetoVG\Documents\teste.pdf');
vpdf.free;

ShellExecute(Handle, nil, PChar('C:\Users\BetoVG\Documents\teste.pdf'), nil, nil, SW_SHOWNORMAL);
end;


thanks

Comments

  • edited 10:01AM
    after several attempts, I found that solution for my case:

    procedure TForm1.SpeedButton6Click(Sender: TObject);
    var i,w,h:integer;
    EMF: TMetafile;
    EMFCanvas: TMetafileCanvas;
    PageInfo: PfrPageInfo;
    vpdf : TPdfDocumentGDI;
    OutDC: HDC;
    begin
    OutDC := Canvas.Handle;
    LogX := GetDeviceCaps(OutDC, LOGPIXELSX);
    LogY := GetDeviceCaps(OutDC, LOGPIXELSY);

    PDFEscx :=strtofloat(edit1.text);
    PDFEscy :=strtofloat(edit1.text);


    frReport1.LoadFromFile('C:\Program Files (x86)\Delphi7SE\Testes\FreeReport\Simples\TESTE.frf');
    frReport1.ShowProgress:=false;
    frReport1.PrepareReport;

    vpdf := TPdfDocumentGDI.Create;
    vpdf.GeneratePDF15File:=true;
    vpdf.CompressionMethod := cmNone;

    vPdf.DefaultPaperSize := psA4; // setup for standard 8.5x11 Letter
    vPdf.ScreenLogPixels := 72;
    for i:=0 to frReport1.EMFPages.Count-1 do begin
    PageInfo :=frReport1.EMFPages;

    EMF := TMetafile.Create;
    w:=trunc(PageInfo.prninfo.pgw/logX*vpdf.ScreenLogPixels);
    h:=trunc(PageInfo.prninfo.pgh/logY*vpdf.ScreenLogPixels);


    EMF.Width := w;
    EMF.Height := h;

    EMFCanvas := TMetafileCanvas.Create(EMF, 0);


    PageInfo.Visible := True;
    frReport1.EMFPages.Draw(i, EMFCanvas,
    Rect(0, 0, w, h));


    vpdf.AddPage;

    EMFCanvas.Free;

    vPdf.Canvas.RenderMetaFile(emf, 1, 0, 0, tpExactTextCharacterPositining);


    EMF.Free;
    end;

    vpdf.SaveToFile('C:\Users\BetoVG\Documents\teste.pdf');
    vpdf.free;

    ShellExecute(Handle, nil, PChar('C:\Users\BetoVG\Documents\teste.pdf'), nil, nil, SW_SHOWNORMAL);
    end;


Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.