You are not logged in.
Pages: 1
I am trying to export to pdf, but the pdf page is generated inconsistent where the height, width and font size are not equivalent to the previewed page FreeReport.
Could anyone help me?
procedure TForm1.SpeedButton6Click(Sender: TObject);
var i:integer;
EMF: TMetafile;
EMFCanvas: TMetafileCanvas;
PageInfo: PfrPageInfo;
vpdf : TPdfDocumentGDI;
begin
frReport1.LoadFromFile('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[i];
EMF := TMetafile.Create;
EMF.Width := PageInfo.prninfo.pgw;
EMF.Height := PageInfo.prninfo.pgh;
EMFCanvas := TMetafileCanvas.Create(EMF, 0);
PageInfo.Visible := True;
frReport1.EMFPages.Draw(i, EMFCanvas,
Rect(0, 0, PageInfo.PrnInfo.pgw, PageInfo.PrnInfo.pgh));
vpdf.DefaultPageWidth := MulDiv(PageInfo.PrnInfo.pgw,72,vPdf.ScreenLogPixels);
vPdf.DefaultPageHeight := MulDiv(PageInfo.PrnInfo.pgw,72,vPdf.ScreenLogPixels);
vpdf.AddPage;
EMFCanvas.Free;
vpdf.VCLCanvas.Draw(0,0,EMF);
EMF.Free;
end;
vpdf.SaveToFile('teste.pdf');
vpdf.free;
ShellExecute(Handle, nil, PChar('teste.pdf'), nil, nil, SW_SHOWNORMAL);
end;
Thanks
Offline
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[i];
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;
Offline
Pages: 1