Recent

Author Topic: [SOLVED] Not able to Create PDF Using fppdf [TAG : fcl-pdf, fppdf]  (Read 3125 times)

heejit

  • Full Member
  • ***
  • Posts: 245
Error on following statment

APage.WriteText(10, 10, 'hello test');  --> Error List Index(0) out of bounds
 

Code: Pascal  [Select][+][-]
  1. procedure CreatePDf();
  2. var
  3.   APdf  : TPDFDocument;
  4.   ASec  : TPDFSection;
  5.   APage : TPDFPage;
  6.   AFile : TFileStream;
  7.   AFont : Integer;
  8. begin
  9.   // create pdf document
  10.   APdf  := TPDFDocument.Create(Nil);
  11.   APdf.Options := [poPageOriginAtTop];
  12.   AFont := APdf.AddFont('Helvetica');
  13.   APdf.StartDocument;
  14.  
  15.   // create section
  16.   ASec  := apdf.Sections.AddSection;
  17.  
  18.   // create page
  19.   APage := Apdf.Pages.AddPage;
  20.   Apage.Orientation    := ppoPortrait;
  21.   APage.PaperType     := ptA4;
  22.   APage.UnitOfMeasure := uomPixels;
  23.   ASec.AddPage(APage); // Add the Page to the Section
  24.  
  25.   // draw
  26.   APage.SetFont(AFont, 10);
  27.   APage.WriteText(10, 10, 'hello test');  --> Error List Index(0) out of bounds
  28.  
  29.   // save
  30.   AFile := TFileStream.Create('test.pdf',fmCreate);
  31.   APdf.SaveToStream(AFile);
  32.  
  33.   AFile.Free;
  34.   APage.Free;
  35.   ASec.Free;
  36.   APdf.Free;
  37.  
  38. end;
  39.  

« Last Edit: December 19, 2018, 05:43:54 pm by jshah »

heejit

  • Full Member
  • ***
  • Posts: 245
Re: PDF Create Using fclpdf/fppdf Error
« Reply #1 on: December 19, 2018, 03:39:11 pm »
Please help

Even I am not able to run the example in fcl-pdf

It showing font helvetica not found

this is related to FONT issue
 
« Last Edit: December 19, 2018, 03:40:57 pm by jshah »

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Not able to Create PDF Using fppdf [TAG : fcl-pdf, fppdf]
« Reply #2 on: December 19, 2018, 05:35:54 pm »
I've never used it so I'm not sure at all but from looking to the examples, shouldn't StartDocument be called before doing anything else?

Code: Pascal  [Select][+][-]
  1. procedure CreatePDf();
  2. var
  3.   APdf  : TPDFDocument;
  4.   ASec  : TPDFSection;
  5.   APage : TPDFPage;
  6.   AFile : TFileStream;
  7.   AFont : Integer;
  8. begin
  9.   // create pdf document
  10.   APdf  := TPDFDocument.Create(Nil);
  11.   APdf.Options := [poPageOriginAtTop];
  12.   APdf.StartDocument;
  13.   AFont := APdf.AddFont('Helvetica');
  14.  
  15.   // create section
  16.   ASec  := apdf.Sections.AddSection;
  17.  
  18.   // create page
  19.   APage := Apdf.Pages.AddPage;
  20.   Apage.Orientation    := ppoPortrait;
  21.   APage.PaperType     := ptA4;
  22.   APage.UnitOfMeasure := uomPixels;
  23.   ASec.AddPage(APage); // Add the Page to the Section
  24.  
  25.   // draw
  26.   APage.SetFont(AFont, 10);
  27.   APage.WriteText(10, 10, 'hello test');  --> Error List Index(0) out of bounds
  28.  
  29.   // save
  30.   AFile := TFileStream.Create('test.pdf',fmCreate);
  31.   APdf.SaveToStream(AFile);
  32.  
  33.   AFile.Free;
  34.   APage.Free;
  35.   ASec.Free;
  36.   APdf.Free;
  37.  
  38. end;
  39.  
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

heejit

  • Full Member
  • ***
  • Posts: 245
Re: Not able to Create PDF Using fppdf [TAG : fcl-pdf, fppdf]
« Reply #3 on: December 19, 2018, 05:43:43 pm »
Yes that is one issue corrected
and it is working now

fcl-pdf example also working after
copying some ttf font file to fonts sub-directory of project directory



« Last Edit: December 19, 2018, 06:00:10 pm by jshah »

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: [SOLVED] Not able to Create PDF Using fppdf [TAG : fcl-pdf, fppdf]
« Reply #4 on: December 19, 2018, 06:58:30 pm »
Not an expert, but it seems likely that APage and ASec are owned by APdf, so:

    APage.Free;
    ASec.Free;

may cause problems.

I found the first issue, lucamar beat me to the punch :), but only got it running after commenting out the above two lines.
« Last Edit: December 19, 2018, 07:02:55 pm by VTwin »
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: [SOLVED] Not able to Create PDF Using fppdf [TAG : fcl-pdf, fppdf]
« Reply #5 on: December 19, 2018, 07:15:40 pm »
Not an expert, but it seems likely that APage and ASec are owned by APdf, so:

    APage.Free;
    ASec.Free;

may cause problems.

I found the first issue, lucamar beat me to the punch :), but only got it running after commenting out the above two lines.

Humm ... You may be right. One way to know it for sure is to use heaptrc to see if just with APdf.Free everything else gets also freed. Or looking into the source.

Now my curiosity is piked! I'll have to try some simple example later. Damn, there goes my sleep-time :)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: [SOLVED] Not able to Create PDF Using fppdf [TAG : fcl-pdf, fppdf]
« Reply #6 on: December 19, 2018, 07:21:30 pm »
Now my curiosity is piked! I'll have to try some simple example later. Damn, there goes my sleep-time :)

No kidding, it is more fun than what I'm supposed to be doing. :D

I have a library that outputs vector graphics to svg, eps, and dxf. Now I have to add pdf!
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: [SOLVED] Not able to Create PDF Using fppdf [TAG : fcl-pdf, fppdf]
« Reply #7 on: December 19, 2018, 07:24:57 pm »
I have a library that outputs vector graphics to svg, eps, and dxf. Now I have to add pdf!

Oh, nice! Is it publicly available? Just svg and pdf would be more then enough for me.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: [SOLVED] Not able to Create PDF Using fppdf [TAG : fcl-pdf, fppdf]
« Reply #8 on: December 19, 2018, 07:59:29 pm »
I have a library that outputs vector graphics to svg, eps, and dxf. Now I have to add pdf!

Oh, nice! Is it publicly available? Just svg and pdf would be more then enough for me.

Thanks. It is in the works to open up, hopefully in next month or so. It is a 2D graphics system with basic 3D functionality, and includes an extensive matrix library. Graphics are created in a vgraphic object that contains a list of layers, which contain vector graphics objects. The vgraphic object is then rendered to raster or file vector formats. The raster output uses BGRABitmap, so has transparancy. svg and eps are in good shape, pdf is just starting.

I'll pm you a link to my software page, all the graphics are done with vgraphic.
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: [SOLVED] Not able to Create PDF Using fppdf [TAG : fcl-pdf, fppdf]
« Reply #9 on: December 19, 2018, 09:07:40 pm »
Thanks. It is in the works to open up, hopefully in next month or so. It is a 2D graphics system with basic 3D functionality, and includes an extensive matrix library. Graphics are created in a vgraphic object that contains a list of layers, which contain vector graphics objects. The vgraphic object is then rendered to raster or file vector formats. The raster output uses BGRABitmap, so has transparancy. svg and eps are in good shape, pdf is just starting.

I'll pm you a link to my software page, all the graphics are done with vgraphic.

Sounds very interesting! ;D
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

heejit

  • Full Member
  • ***
  • Posts: 245
Re: [SOLVED] Not able to Create PDF Using fppdf [TAG : fcl-pdf, fppdf]
« Reply #10 on: December 23, 2018, 03:32:18 pm »
yes Apdf.free is enough to release asec, apage

 

TinyPortal © 2005-2018