LazReport, Implemented PDF export

git-svn-id: trunk@16900 -
This commit is contained in:
jesus 2008-10-06 14:43:45 +00:00
parent 6361b90a57
commit 70dafcbd7b
7 changed files with 443 additions and 0 deletions

6
.gitattributes vendored
View File

@ -502,6 +502,12 @@ components/lazreport/source/addons/addfunction/lrAddFunctionLibrary.pas svneol=n
components/lazreport/source/addons/addfunction/lr_add_function.lpk svneol=native#text/plain
components/lazreport/source/addons/addfunction/lr_add_function.pas svneol=native#text/pascal
components/lazreport/source/addons/addfunction/lr_add_function_const.pas svneol=native#text/pascal
components/lazreport/source/addons/pdfexport/lazreportpdfexport.lpk svneol=native#text/plain
components/lazreport/source/addons/pdfexport/lazreportpdfexport.pas svneol=native#text/plain
components/lazreport/source/addons/pdfexport/lr_e_pdf.pas svneol=native#text/plain
components/lazreport/source/addons/pdfexport/lr_pdfexp_reg.lrs svneol=native#text/plain
components/lazreport/source/addons/pdfexport/lr_pdfexp_reg.pas svneol=native#text/plain
components/lazreport/source/addons/pdfexport/tfrtnpdfexport.png -text svneol=unset#image/png
components/lazreport/source/barcode.pas svneol=native#text/pascal
components/lazreport/source/fr_pencil.lrs svneol=native#text/plain
components/lazreport/source/languages/lr_const.de.po svneol=native#text/plain

View File

@ -0,0 +1,64 @@
<?xml version="1.0"?>
<CONFIG>
<Package Version="3">
<PathDelim Value="\"/>
<Name Value="lazreportpdfexport"/>
<Author Value="Jesus Reyes A."/>
<CompilerOptions>
<Version Value="8"/>
<PathDelim Value="\"/>
<SearchPaths>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Parsing>
<SyntaxOptions>
<CStyleOperator Value="False"/>
</SyntaxOptions>
</Parsing>
<Other>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
<Description Value="PDF Exporter for PDF
"/>
<Version Minor="5"/>
<Files Count="2">
<Item1>
<Filename Value="lr_e_pdf.pas"/>
<UnitName Value="lr_e_pdf"/>
</Item1>
<Item2>
<Filename Value="lr_pdfexp_reg.pas"/>
<HasRegisterProc Value="True"/>
<UnitName Value="lr_pdfexp_reg"/>
</Item2>
</Files>
<Type Value="RunAndDesignTime"/>
<RequiredPkgs Count="5">
<Item1>
<PackageName Value="IDEIntf"/>
</Item1>
<Item2>
<PackageName Value="LCL"/>
</Item2>
<Item3>
<PackageName Value="pack_powerpdf"/>
<MinVersion Minor="9" Valid="True"/>
</Item3>
<Item4>
<PackageName Value="lazreport"/>
</Item4>
<Item5>
<PackageName Value="FCL"/>
<MinVersion Major="1" Valid="True"/>
</Item5>
</RequiredPkgs>
<UsageOptions>
<UnitPath Value="$(PkgOutDir)\"/>
</UsageOptions>
<PublishOptions>
<Version Value="2"/>
<IgnoreBinaries Value="False"/>
</PublishOptions>
</Package>
</CONFIG>

View File

@ -0,0 +1,21 @@
{ This file was automatically created by Lazarus. do not edit!
This source is only used to compile and install the package.
}
unit lazreportpdfexport;
interface
uses
lr_e_pdf, lr_pdfexp_reg, LazarusPackageIntf;
implementation
procedure Register;
begin
RegisterUnit('lr_pdfexp_reg', @lr_pdfexp_reg.Register);
end;
initialization
RegisterPackage('lazreportpdfexport', @Register);
end.

View File

@ -0,0 +1,303 @@
{****************************************************}
{ }
{ FastReport v2.3 }
{ PDF export filter Ver 1.0 }
{ }
{ By : Ricardo Cardona Ramirez }
{ }
{ PowerPDF }
{ http://www.est.hi-ho.ne.jp/takeshi_kanno/powerpdf/ }
{ ZLib Units Delphi 5-6 }
{ http://www.base2ti.com/zlib.htm }
{ }
{****************************************************}
unit lr_e_pdf;
{$mode objfpc}{$H+}
interface
uses
SysUtils, Windows, Messages, Classes, Graphics, Forms, StdCtrls, lr_BarC,
lr_class, PdfDoc, PdfTypes, PdfFonts, PReport, Dialogs, Controls;
type
TfrTNPDFExport = class(TComponent) // fake component
end;
TfrTNPDFExportFilter = class(TfrExportFilter)
private
NewPage: Boolean;
PDF: TPReport;
PPage: TPRPage;
PRPanel: TPRPanel;
FOutline: TPROutLineEntry;
FPageNo : Integer;
DummyControl: TForm;
public
constructor Create(AStream: TStream); override;
destructor Destroy; override;
procedure OnBeginPage; override;
procedure OnEndPage; override;
procedure ShowBackGround(View: TfrView; x, y, h, w: integer);
procedure Frame(View: TfrView; x, y, h, w: integer);
procedure ShowFrame(View: TfrView; x, y, h, w: integer);
procedure ShowBarCode(View: TfrBarCodeView; x, y, h, w: integer);
procedure ShowPicture(View: TfrPictureView; x, y, h, w: integer);
procedure OnText(X, Y: Integer; const Text: string; View: TfrView);
override;
procedure OnData(x, y: Integer; View: TfrView); override;
end;
implementation
uses lr_Const;
type
TfrMemoView_ = class(TfrMemoView);
TPRText_ = class(TPRText);
const
PDFEscx = 0.8;
PDFEscy = 0.8;
constructor TfrTNPDFExportFilter.Create(AStream: TStream);
begin
inherited;
PDF := TPReport.Create(nil);
//PDF.CompressionMethod := cmFlateDecode;
PDF.UseOutlines := True;
PDF.PageLayout := plOneColumn;
PDF.BeginDoc;
DummyControl := TForm.Create(nil);
NewPage := False;
FPageNo := 0;
end;
destructor TfrTNPDFExportFilter.Destroy;
begin
PDF.GetPdfDoc.SaveToStream(Stream);
PDF.Free;
DummyControl.Free;
inherited;
end;
procedure TfrTNPDFExportFilter.OnBeginPage;
begin
{Add New Page}
Inc(FPageNo);
PPage := TPRPage.Create(PDF);
PPage.Parent := DummyControl;
PPage.MarginBottom := 0;
PPage.MarginTop := 0;
PPage.MarginLeft := 0;
PPage.MarginRight := 0;
PPage.Height := trunc(CurReport.EMFPages[FPageNo - 1]^.PrnInfo.Pgh*PDFEscy);
PPage.Width := trunc(CurReport.EMFPages[FPageNo - 1]^.PrnInfo.Pgw*PDFEscx);
PRPanel := TPRPanel.Create(PPage);
PRPanel.Parent := PPage;
PRPanel.Left := 0;
PRPanel.Top := 0;
PRPanel.Width := PPage.Width;
PRPanel.Height := PPage.Height;
end;
procedure TfrTNPDFExportFilter.OnEndPage;
begin
PDF.Print(PPage);
FOutline := PDF.OutlineRoot.AddChild;
FOutline.Dest := PDF.CreateDestination;
FOutline.Dest.Top := 0;
FOutline.Title := 'Page ' + IntToStr(FPageNo);
FreeAndNil(PPage);
end;
procedure TfrTNPDFExportFilter.ShowBackGround(View: TfrView; x, y, h, w:
integer);
var
PRRect: TPRRect;
begin
PRRect := TPRRect.Create(PRPanel);
PRRect.Parent := PRPanel;
PRRect.FillColor := View.FillColor;
PRRect.LineColor := clNone;
PRRect.LineStyle := psSolid;
PRRect.Left := x;
PRRect.Top := y;
PRRect.Height := h;
PRRect.Width := w;
end;
procedure TfrTNPDFExportFilter.Frame(View: TfrView; x, y, h, w: integer);
var
PRRect: TPRRect;
begin
PRRect := TPRRect.Create(PRPanel);
PRRect.Parent := PRPanel;
PRRect.FillColor := clNone;
PRRect.Left := x;
PRRect.Top := y;
PRRect.Height := h;
PRRect.Width := w;
PRRect.LineStyle := TPenStyle(View.FrameStyle);
PRRect.LineWidth := View.FrameWidth - 0.5;
PRRect.LineColor := View.FrameColor;
end;
procedure TfrTNPDFExportFilter.ShowFrame(View: TfrView; x, y, h, w: integer);
begin
if ([frbLeft,frbTop,frbRight,frbBottom]-View.Frames=[]) and
(View.FrameStyle = frsSolid) then
begin
Frame(View, x, y, h, w);
end
else
begin
if frbRight in View.Frames then
Frame(View, x + w - 1, y, h, 0); //Right
if frbLeft in View.Frames then
Frame(View, x, y, h, 0); //Left
if frbBottom in View.Frames then
Frame(View, x, y + h - 1, 0, w); //Botton
if frbTop in View.Frames then
Frame(View, x, y, 0, w); //Top
end;
end;
procedure TfrTNPDFExportFilter.ShowBarCode(View: TfrBarCodeView; x, y, h, w:
integer);
var
Bitmap: TBitmap;
PRImage: TPRImage;
oldX, oldY: Integer;
begin
oldX := View.x;
oldy := View.y;
View.x := 0;
View.y := 0;
Bitmap := TBitmap.Create;
try
PRImage := TPRImage.Create(PRPanel);
PRImage.Parent := PRPanel;
PRImage.Stretch := True;
PRImage.SharedImage := False;
PRImage.Left := x;
PRImage.Top := y;
PRImage.Height := h;
PRImage.Width := w;
Bitmap.Height := View.dy;
Bitmap.Width := View.dx;
TfrBarCodeView(View).Draw(Bitmap.Canvas);
PRImage.Picture.Bitmap := Bitmap;
finally
FreeAndNil(Bitmap);
end;
View.x := oldX;
View.y := oldY;
end;
procedure TfrTNPDFExportFilter.ShowPicture(View: TfrPictureView; x, y, h,
w: integer);
var
Bitmap: TBitmap;
PRImage: TPRImage;
begin
Bitmap := TBitmap.Create;
try
PRImage := TPRImage.Create(PRPanel);
PRImage.Parent := PRPanel;
PRImage.Stretch := True;
PRImage.SharedImage := False;
PRImage.Left := x;
PRImage.Top := y;
PRImage.Height := h;
PRImage.Width := w;
Bitmap.Height := View.Picture.Height;
Bitmap.Width := View.Picture.Width;
Bitmap.Canvas.Draw(0, 0, View.Picture.Graphic);
PRImage.Picture.Bitmap := Bitmap;
finally
FreeAndNil(Bitmap);
end;
end;
procedure TfrTNPDFExportFilter.OnData(x, y: Integer; View: TfrView);
var
nx, ny, ndx, ndy: Integer;
begin
nx := Round(x * PDFEscx);
ny := Round(y * PDFEscy);
ndx := Round((View.dx) * PDFEscx + 1) ;
ndy := Round((View.dy) * PDFEscy + 1) ;
if View.FillColor <> clNone then
ShowBackGround(View, nx, ny, ndy, ndx);
if View is TfrBarCodeView then
ShowBarCode(TfrBarCodeView(View), nx, ny, ndy, ndx)
else if View is TfrPictureView then
ShowPicture(TfrPictureView(View), nx, ny, ndy, ndx);
// For debugging only
// else if not View is TfrMemoView then
// MessageDlg(View.ClassName, mtWarning, [mbOK], 0);
if (View.Frames<>[]) and not (View is TfrBarCodeView) then
ShowFrame(View, nx, ny, ndy, ndx);
end;
procedure TfrTNPDFExportFilter.OnText(X, Y: Integer; const Text: string;
View: TfrView);
var
PRTLabel: TPRText;
nx, ny,
ndx, ndy: Integer;
begin
nx := Round(x * PDFEscx) + 1;
ny := Round(y * PDFEscy) + 1;
ndx := Round(View.dx * PDFEscx);
ndy := Round(View.dy * PDFEscy);
PRTLabel := TPRText.Create(PRPanel);
PRTLabel.Parent := PRPanel;
try
PRTLabel.Text := Text;
PRTLabel.Left := nx;
PRTLabel.Top := ny;
PRTLabel.Width := ndx;
PRTLabel.Height := ndy;
if View is TfrMemoView then
begin
if Pos('Arial', TfrMemoView_(View).Font.Name) > 0 then
PRTLabel.FontName := fnArial
else if Pos('Courier', TfrMemoView_(View).Font.Name) > 0 then
PRTLabel.FontName := fnFixedWidth
else if Pos('Times', TfrMemoView_(View).Font.Name) > 0 then
PRTLabel.FontName := fnTimesRoman;
PRTLabel.FontSize := TfrMemoView_(View).Font.Size;
PRTLabel.FontBold := fsBold in TfrMemoView_(View).Font.Style;
PRTLabel.FontItalic := fsItalic in TfrMemoView_(View).Font.Style;
PRTLabel.FontColor := TfrMemoView_(View).Font.Color;
end;
finally
end;
end;
initialization
frRegisterExportFilter(TfrTNPDFExportFilter, 'Adobe Acrobat PDF ' + ' (*.pdf)',
'*.pdf');
end.

View File

@ -0,0 +1,26 @@
LazarusResources.Add('tfrtnpdfexport','PNG',[
#137'PNG'#13#10#26#10#0#0#0#13'IHDR'#0#0#0#24#0#0#0#24#8#6#0#0#0#224'w='#248#0
+#0#0#1'sRGB'#0#174#206#28#233#0#0#0#6'bKGD'#0#255#0#255#0#255#160#189#167#147
+#0#0#0#9'pHYs'#0#0#11#19#0#0#11#19#1#0#154#156#24#0#0#0#7'tIME'#7#216#10#6#5
+':'#14#153#184'B'#10#0#0#1#212'IDATH'#199'c`'#160'1`d```HKM'#253'O'#172#134
+'Y'#179'g3'#146'lKZj'#234'b@Zj'#234#255#147#199#143#255''''#197'l'#22'd'#142
+#135#155#27'N'#133';v'#237'"+'#136'X'#168'a'#8#209#22'p'#153'W10000|;'#217
+#134#225#155#29#187'v1'#24#4'41'#228'/'#189#206'`'#145#179#15#30'Lq'#158#154
+#12'Y'#222#146#140'DY@'#138'o'#226'<5'#25#24#24#24#24#22'm'#191#206'0m'#235
+#243#255#184','#193'i'#1'6'#31'\'#216'P'#199'01)'#137#225#236';'#5#134'E'#219
+#175'3'#196'yj2'#196'yj'#226#181#4#197#130'o'''#219#136#242'A'#150#183'$'#227
+#180#173#207#255#163'[B'#243'T'#132#205#23'd'#165'"'#139#156'}p'#215'#'#199
+#201#162#237#144#4'pb'#138#19'#'#209'>'#216#177'k'#23#131#135#155#27#138#229
+#248#130'$'#206'S'#147#225#196#20#18'}'#128'.'#142#30#7#176#212#132'-'#201
+#194'-HOK#)'#3'!['#130'/?'#192#5#208#203#152'C'#202#171#137#178'('#250#238'-'
+#6#6#6#6#134#165#202'j'#24'r'#165'b}'#140'8s`'#247#171#162#255'[n'#174'$'#187
+#136'x5'#251'?'#195#245'E'#207#24'Y'#8')<`'#243#132#225#207#191#223#12'[_'
+#174'`'#232#191'['#201'p'#192#230#9#195#191#255#255#24#158#253'x'#200#208''
+#183#138#225#236#135#195'pu0'#224'pD'#6#206'f"'#198'5'#17'g,'#25'<'#196'B'
+#224'|'#151#163#10#12#243#31#245'2'#20'*'#183#161#168's8"'#131'b8'#209#22#172
+'09'#206#176#235#245'Z8'#255#31#195'?'#134#195'o'#182'3Hp'#200'b'#248#22#217
+'''x'#203'"d'#224'rL'#17#205'UL'#12#182'"'#158#12'/~<'#194#240#1#209#133#29
+'>'#176#215#250'!'#195#211#31#15#24#250#239'V'#145'V'#31'`'#3#232#174#194#230
+'J|'#226','#132#146#218#160#7#0#180#200#246#157'k|'#166'!'#0#0#0#0'IEND'#174
+'B`'#130
]);

View File

@ -0,0 +1,23 @@
unit lr_pdfexp_reg;
{$mode objfpc}{$H+}
interface
uses
classes, LResources, lr_e_pdf;
procedure register;
implementation
procedure register;
begin
RegisterComponents('LazReport', [TfrTNPDFExport]);
end;
initialization
{$I lr_pdfexp_reg.lrs}
end.

Binary file not shown.

After

Width:  |  Height:  |  Size: 596 B