#1 2010-06-30 16:42:07

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 12,997
Website

Using SQLite3Pages as a stand-alone report maker

Did you notice the SQLite3Pages units?
It's a reporting unit included in our SQlite3 framework, but it can be used standalone...

You create your report from code, then you can preview it on the screen.
You can then print or export the report as PDF.
Note that the report drawing uses GDI+, even if you embed .emf files or TMetaFile in them: with antialiaising, they just look smooth on screen.

Just right click on the report preview to see options.

Here is some code sample to create a report:

procedure TForm1.btn1Click(Sender: TObject);
var i: integer;
begin
  with TGDIPages.Create(self) do
  try
    // the title of the report
    Caption := self.Caption;
    // now we add some content to the report
    BeginDoc;
    // header and footer
    AddTextToHeader(paramstr(0));
    SaveLayout;
    Font.Style := [fsItalic];
    TextAlign := taRight;
    AddTextToFooterAt('http://synopse.info',RightMarginPos);
    RestoreSavedLayout;
    AddTextToFooter(DateTimeToStr(Now));
    // main content (automaticaly split on next pages)
    NewHalfLine;
    DrawTitle(edt1.Text,true);
    for i := 1 to 10 do
      DrawText('This is some text '+IntToStr(i));
    NewLine;
    AddColumns([10,20,50]);
    AddColumnHeaders(['#','Two','Three'],true,true);
    for i := 1 to 100 do
      DrawTextAcrossCols([IntToStr(i),'Column '+IntToStr(i),'Some text here']);
    NewLine;
    DrawTitle('This is your text:');
    DrawText(mmo1.Text);
    EndDoc;
    // this method will show a preview form, and allow basic actions
    // by using the right click menu
    ShowPreviewForm;
  finally
    Free;
  end;
end;

You can download a sample project source code (together with its compiled exe file) from http://synopse.info/files/pdf/SQLite3Pages.7z

You should need other Synopse units, available from synpdf.zip.

The resulting pdf file can be downloaded from http://synopse.info/files/pdf/SQLite3Pages%20Test.pdf

Source code is licensed under a MPL/GPL/LGPL tri-license.

Offline

#2 2010-06-30 18:28:20

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 12,997
Website

Re: Using SQLite3Pages as a stand-alone report maker

Of course, TGDIPages is a component. You can put on any form, and customize menus and add buttons to the screen.

Offline

#3 2010-07-31 18:06:40

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 12,997
Website

Re: Using SQLite3Pages as a stand-alone report maker

Here is how to create a report content from a TRichEdit component:

http://synopse.info/forum/viewtopic.php?id=76

Offline

#4 2010-08-15 12:52:55

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 12,997
Website

Re: Using SQLite3Pages as a stand-alone report maker

Note that you have a true Canvas property in the TGDIPages class.

So you can use TGDIPages to create a print preview and pdf export, by using TGDIPages.Canvas instead of Printer.Canvas.

Offline

#5 2010-09-03 07:12:51

eraldo
Member
From: Brasil
Registered: 2010-07-22
Posts: 68
Website

Re: Using SQLite3Pages as a stand-alone report maker

Administrator,

How do you add a bmp image in this example with TGDIPages?
Something like:
Var
  image: TBitmat;

image: TBitmap.Create = (nil)
image.LoadFromFile ('c: \ ...

I appreciate your help

Eraldo

Last edited by eraldo (2010-09-03 07:14:48)

Offline

#6 2011-01-05 06:57:16

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 12,997
Website

Re: Using SQLite3Pages as a stand-alone report maker

To add a bitmap, use the TGDIPages.DrawBMP method.

You can specify a coordinates TRect in which the bitmap is to be stretched.

Offline

#7 2011-01-26 13:38:47

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 12,997
Website

Re: Using SQLite3Pages as a stand-alone report maker

Reporting has just been enhanced (in our source code repository): now handle bookmarks, links, and document outline, and life-navigation within the report preview. The generated PDF file also handle those links and outline tree. Some issues were also fixed (about bitmaps or underlined text). And one bitmap will be stored only once in the PDF, if it's drawn several times on the report.

So make sure you're using the latest source code repository version.

Offline

#8 2011-02-07 20:52:32

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 12,997
Website

Re: Using SQLite3Pages as a stand-alone report maker

Here is some sample code, showing some new features of the SQLite3Pages unit:

procedure TForm1.btn1Click(Sender: TObject);
var i: integer;
    Bmp: TBitmap;
    s: string;
begin
  Bmp := TBitmap.Create;
  try
    Bmp.Width := ClientWidth;
    Bmp.Height := ClientHeight;
    PaintTo(Bmp.Canvas,0,0); // create some bitmap content
    with TGDIPages.Create(self) do
    try
      // the name of the report is taken from main Window's caption
      Caption := self.Caption;
      // now we add some content to the report
      BeginDoc;
      // header and footer
      Font.Name := 'Georgia';
      Font.Size := 11;
      SaveLayout;
      Font.Style := [fsItalic,fsUnderline];
      TextAlign := taRight;
      AddTextToHeaderAt('http://synopse.info',RightMarginPos);
      Font.Style := [];
      AddLineToFooter(false);
      AddPagesToFooterAt('Page %d/%d',RightMarginPos);
      RestoreSavedLayout;
      AddTextToHeader(ExtractFileName(paramstr(0)));
      AddTextToFooter(DateTimeToStr(Now));
      AddLineToHeader(false);
      Font.Size := 12;
      // main content (automaticaly split on next pages)
      NewHalfLine;
      TextAlign := taJustified;
      s := 'This is some big text which must be justified on multiple lines. ';
      DrawText(s+s+s+s);
      NewLine;
      TextAlign := taLeft;
      DrawTitle(edt1.Text,true);
      for i := 1 to 10 do
        DrawText('This is some text '+IntToStr(i));
      NewLine;
      DrawBMP(Bmp,maxInt,50,'Some bitmap in the report');
      AddBookMark('bookmarkname');
      WordWrapLeftCols := true;
      AddColumns([10,20,50]);
      AddColumnHeaders(['#','Two','Three'],true,true);
      for i := 1 to 100 do
        DrawTextAcrossCols([IntToStr(i),'Column '+IntToStr(i),'Some text here. '+s]);
      NewLine;
      DrawBMP(Bmp,maxInt,50,'Some bitmap in the report (twice)');
      DrawTitle('This is your text',false,0,'','bookmarkname');
      DrawText(mmo1.Text);
      EndDoc;
      // set optional PDF export options
      // ExportPDFForceJPEGCompression := 80;
      // ExportPDFEmbeddedTTF := true;
      // ExportPDFUseUniscribe := true;
      // show a preview form, and allow basic actions via the right click menu
      ShowPreviewForm;
      // ExportPDFA1 := true;
      // ExportPDF(ChangeFileExt(paramstr(0),'.pdf'),true,true);
    finally
      Free;
    end;
  finally
    Bmp.Free;
  end;
  Close;
end;

The AddBookMark method is used to create a bookmark at the current Y position.
Then 'bookmarkname' is added to the DrawTitle() method, so that clicking on this title will browse back to the bookmark position.

All titles are now automatically added to the global outline of the document, which is accessible via the right click menu.

During the export to PDF, all outilines and links are also handled and exported as such.
smile

Offline

#9 2015-11-20 12:18:37

yogiyang
Member
Registered: 2010-08-18
Posts: 23

Re: Using SQLite3Pages as a stand-alone report maker

Hello,

I am trying to use the code in Post #8 in Delphi XE6 and am getting errors like DrawBMP not found.

Am I missing something here?

TIA

Yogi Yang

Offline

#10 2015-11-20 12:38:56

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 12,997
Website

Re: Using SQLite3Pages as a stand-alone report maker

I guess you are using an old version of the unit.

Please download the latest version from the trunk.
The easiest is to download via http://synopse.info/files/mORMotNightlyBuild.zip and get the units you need.
See also http://synopse.info/files/html/Synopse% … l#TITL_113

Offline

#11 2015-11-20 13:49:46

yogiyang
Member
Registered: 2010-08-18
Posts: 23

Re: Using SQLite3Pages as a stand-alone report maker

Thanks,

I have managed to solve my problem.

I had to update the file SynCommons.pas

with these lines:
    {$elseif defined(VER250)} 'Delphi XE4'
    {$elseif defined(VER260)} 'Delphi XE5'
    {$elseif defined(VER270)} 'Delphi XE6'

Offline

#12 2015-11-20 13:59:42

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 12,997
Website

Re: Using SQLite3Pages as a stand-alone report maker

Your library code is outdated!

Use the latest version, as I wrote.

Offline

#13 2015-11-20 14:39:27

yogiyang
Member
Registered: 2010-08-18
Posts: 23

Re: Using SQLite3Pages as a stand-alone report maker

Ok thanks.

Offline

#14 2015-11-24 04:27:13

yogiyang
Member
Registered: 2010-08-18
Posts: 23

Re: Using SQLite3Pages as a stand-alone report maker

Hello again,

I have got around 1000 images in one single folder.

I am trying to get their thumbnails to print like http://s3.postimg.org/dj4witwk3/2015_11_23_213907.jpg

But I am getting only image per line instead of multiple images on the same line.

Here is the main code that I am using for inserting image in PDF

LL := Col * 2500;

Bmp.Assign(ieTemp.Bitmap);
DrawBMP(Bmp,LL,50,FileName)

Col := Col +1;

What mistake am I making here?

TIA

Yogi Yang

Offline

#15 2015-11-24 14:32:13

yogiyang
Member
Registered: 2010-08-18
Posts: 23

Re: Using SQLite3Pages as a stand-alone report maker

ab wrote:

DrawBMP(Bmp,maxInt,50,'Some bitmap in the report');

In this line why do you use maxInt?

If I try to use any other value the image just does not print. Why?

TIA

Yogi Yang

Offline

#16 2017-07-05 16:13:11

dhawk
Member
Registered: 2017-07-05
Posts: 1

Re: Using SQLite3Pages as a stand-alone report maker

I am attempting to get this demo to work with the latest sources (from the nightly build, no less).  The preview looks fine, but when I attempt "PDF Export" all I get is three blank pages.  If I Print to Microsoft PDF printer it works.   I am using XE5 on Win10/64.

Any suggestions?

Thanks,
Dave

p.s. The "PDF Export" function from the pre-compiled demo TestSQLite3Pages.exe (compiled in 2010) works properly on my system.

Offline

#17 2017-07-05 16:58:53

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 12,997
Website

Re: Using SQLite3Pages as a stand-alone report maker

I am not able to reproduce the problem with Delphi XE4, targetting Win32 or Win64.

Offline

Board footer

Powered by FluxBB