export easy using synpdf (synopse) (free)
Posted: Tue Jun 25, 2013 6:01 pm
For those who are tired of trying to solve bugs with eDocEngine to export to pdf like me, here below is a solution using the synopsis that appears to be simple and only with time we will have the solution (final - I hope).
_without having to worry about header and footer
_the first tests this unit is work fine in Delphi 7 and Windows 7
I got some references here on this forum in http://www.trichview.com/forums/viewtop ... t=metafile
(work with SRichViewEdit)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Thanks
_without having to worry about header and footer
_the first tests this unit is work fine in Delphi 7 and Windows 7
I got some references here on this forum in http://www.trichview.com/forums/viewtop ... t=metafile
(work with SRichViewEdit)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Code: Select all
unit UnExpParaPDF;
interface
Uses Windows,Types,Graphics,Forms,SclRView,RVStyle,SysUtils,Dialogs,
ShellAPI,
Synpdf,SynGdiPlus; //synopse
//Formxx.Handle
procedure ExportaParaPdf ( handle:HWND; srve :TSRichViewEdit);
implementation
function MakePageMetafile(srve:TSRichViewEdit;aPageNo, aWidth, aHeight: Integer): TMetafile;
var
savTextDraw: Boolean;
begin
savTextDraw := ScaleRichViewTextDrawAlwaysUseGlyphs;
ScaleRichViewTextDrawAlwaysUseGlyphs := False;
Result := TMetafile.Create;
Result.Width := aWidth;
Result.Height := aHeight;
srve.CanUpdate := False;
srve.UseDrawHyperlinksEvent := True;
srve.DrawMetafile(aPageNo, Result, False, True, False);
ScaleRichViewTextDrawAlwaysUseGlyphs := savTextDraw;
srve.CanUpdate := True;
srve.UseDrawHyperlinksEvent := False;
end;
procedure ExportaParaPdf ( handle:HWND; srve :TSRichViewEdit);
const
OutputFileName = 'c:\teste\testepdf.pdf';
var
i: Integer;
Metafile: TMetafile;
RVUnit: TRVUnits;
R : TRect;
//synopse
PdfDoc : TPDFDocumentGDI;
PdfPage : TPdfpage;
begin
srve.Update; //srve is ScaleRichViewComponent
RVUnit := srve.UnitsProgram; //Get the current value
srve.UnitsProgram := rvuPixels; //Change DBSRichviewEdit to pixels for PDF Conversion
PdfDoc := TPdfDocumentGDI.Create;
for i := 1 to srve.PageCount do
begin
Metafile := MakePageMetafile(srve,i, Round(srve.PageProperty.PageWidth), Round(srve.PageProperty.PageHeight));
try
PdfPage := PdfDoc.AddPage;
if i=1 then begin
PdfDoc.CompressionMethod := cmFlateDecode;
pdfdoc.UseFontFallBack:=true;
PdfDoc.UseSetTextJustification := False;
PdfDoc.DefaultPaperSize := psA4;
PdfDoc.DefaultPageLandscape := False;
PdfDoc.VCLCanvas.Font.Charset:=ANSI_CHARSET;
PdfDoc.UseUniscribe:=False;
end;
// PdfDoc.VCLCanvas.StretchDraw( Rect(0, 0, Round(Screen.PixelsPerInch * Metafile.MMWidth / 3600), Round(Screen.PixelsPerInch * Metafile.MMHeight / 3600)), Metafile);
PdfDoc.VCLCanvas.StretchDraw( Rect(0, 0, Round(srve.PageProperty.PageWidth), Round(srve.PageProperty.PageHeight)), Metafile);
finally
Metafile.Free;
end;
end;
srve.UnitsProgram := RVUnit; //Change back to the previous value before converted to pixels
PdfDoc.SaveToFile(OutputFileName);
PdfDoc.Free;
ShellExecute(Handle, nil, PChar(OutputFileName), nil, nil, SW_SHOWNORMAL);
end;
end.