Recent

Author Topic: SAVE StringGrid to PDF  (Read 4686 times)

seghele0

  • Sr. Member
  • ****
  • Posts: 253
Re: SAVE StringGrid to PDF
« Reply #15 on: December 09, 2024, 06:15:08 pm »
Attached is the latest updated version.
The header is still missing.
Thanks in advance.
 ;)

dseligo

  • Hero Member
  • *****
  • Posts: 1449
Re: SAVE StringGrid to PDF
« Reply #16 on: December 09, 2024, 07:42:30 pm »
Another small problem, I sometimes use the application on a Linux platform (Mint) by using "Wine". The 'exe' works fine via 'wine' but the font selection is a problem.
Maybe it is better not to encode a imposed font, but just the size of 15pt.
Is this possible?
 ;)

This code should compile under Linux, so you don't have to use Wine. You could also ship font you need with your program, and use it so you have same PDF everywhere.

Quote
Sorry, I forgot to mention that the 'Headers' should also be shown on the PDF.

In line 55 you start for loop with 1. Rows in StringGrid are zero based, so change line 55 to:
Code: Pascal  [Select][+][-]
  1.     for i := 0 to StringGrid1.RowCount - 1 do

seghele0

  • Sr. Member
  • ****
  • Posts: 253
Re: SAVE StringGrid to PDF
« Reply #17 on: December 10, 2024, 02:41:16 pm »
Thanks for the quick tip.
I know I'm pushing for improvements to the code, but at 75 years old, things slow down.
As you can see, the PDF (attachment) is not really readable. The columns are too close to each other. Can this be adjusted?
 ;)

dseligo

  • Hero Member
  • *****
  • Posts: 1449
Re: SAVE StringGrid to PDF
« Reply #18 on: December 10, 2024, 02:51:05 pm »
Thanks for the quick tip.
I know I'm pushing for improvements to the code, but at 75 years old, things slow down.

No problem. :)

Quote
As you can see, the PDF (attachment) is not really readable. The columns are too close to each other. Can this be adjusted?
 ;)

In line 60 of last project you sent is where you write text out. You control X (horizontal) position with expression 15 + j * 10. 15 is fixed offset from left side, j is column you write and then you multiply j with 10. Increase this multiplier and you will get wider columns.
I.e.:
Code: Pascal  [Select][+][-]
  1.         Page.WriteText(15 + j * 20, YPos, StringGrid1.Cells[j, i]);

seghele0

  • Sr. Member
  • ****
  • Posts: 253
Re: SAVE StringGrid to PDF
« Reply #19 on: December 10, 2024, 03:24:43 pm »
Incredible and efficient.
Your kind support is an attempt to make the world a better place.
 :)
Thank you all.

dseligo

  • Hero Member
  • *****
  • Posts: 1449
Re: SAVE StringGrid to PDF
« Reply #20 on: December 10, 2024, 04:13:22 pm »
Your kind support is an attempt to make the world a better place.

LOL, I wish it is that simple.

I wanted to mention earlier, but forgot: maybe you already know, but you could also use LazReport (https://wiki.freepascal.org/LazReport_Tutorial) or FPReport (https://wiki.freepascal.org/FPReport_Designer) to design documents and from them create PDF files.
Benefit is that you can visually design documents and this is great when documents become more complex. Also, you can print it directly and export it to other formats. But it also involves learning how to use these components.

jianwt

  • Full Member
  • ***
  • Posts: 126
Re: SAVE StringGrid to PDF
« Reply #21 on: December 11, 2024, 01:41:29 am »
@dseligo. When exporting PDF, can I export StringGrid horizontal and vertical form lines as well?
« Last Edit: December 11, 2024, 01:45:30 am by jianwt »

dseligo

  • Hero Member
  • *****
  • Posts: 1449
Re: SAVE StringGrid to PDF
« Reply #22 on: December 11, 2024, 02:40:40 am »
@dseligo. When exporting PDF, can I export StringGrid horizontal and vertical form lines as well?

Well, you have DrawLine and DrawRect methods in TPDFPage, but you have to calculate coordinates.
I don't know of a simple way to do it like this. That is why, in reply #20, I mentioned that LazReport or FPReport (and probably some other components too) can be used when documents become more complex. Manually creating PDF can quickly become tedious.

seghele0

  • Sr. Member
  • ****
  • Posts: 253
Re: SAVE StringGrid to PDF
« Reply #23 on: December 13, 2024, 04:32:25 pm »
I try to use LazReport as little as possible.
The code you all provided is great.
An additional procedure was added.
There is another request for a line under the heading of the stringgrid, but I get ERROR.
"Line 37: Identifier idents no member "Title".
I hope for a solution.
Thanks.


cdbc

  • Hero Member
  • *****
  • Posts: 1781
    • http://www.cdbc.dk
Re: SAVE StringGrid to PDF
« Reply #24 on: December 13, 2024, 04:38:48 pm »
Hi
Try this:
Code: Pascal  [Select][+][-]
  1.   // Get the bottom position of the StringGrid heading
  2.   Y1 := StringGrid1.Top + StringGrid1.Row[0].Height;
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

seghele0

  • Sr. Member
  • ****
  • Posts: 253
Re: SAVE StringGrid to PDF
« Reply #25 on: December 13, 2024, 05:01:59 pm »
Still ERROR:
Quote
Exit code 1, Errors: 2
unit1.pas(37,43) Error: Illegal qualifier
unit1.pas(37,45) Error: Syntax error, ";" expected but "." found
Code: Pascal  [Select][+][-]
  1.   Y1 := StringGrid1.Top + StringGrid1.Row[0].Height;  


cdbc

  • Hero Member
  • *****
  • Posts: 1781
    • http://www.cdbc.dk
Re: SAVE StringGrid to PDF
« Reply #26 on: December 13, 2024, 05:06:00 pm »
Then go have a looksee in the implementation of TStringgrid.
"Use the Source Luke"
/bc
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

seghele0

  • Sr. Member
  • ****
  • Posts: 253
Re: SAVE StringGrid to PDF
« Reply #27 on: December 13, 2024, 05:19:19 pm »
 :o
Sorry, but I don't get it.
English is not my native language.

dseligo

  • Hero Member
  • *****
  • Posts: 1449
Re: SAVE StringGrid to PDF
« Reply #28 on: December 14, 2024, 05:12:59 pm »
Try this:
Code: Pascal  [Select][+][-]
  1. Y1 := StringGrid1.Top + StringGrid1.RowHeights[0];

seghele0

  • Sr. Member
  • ****
  • Posts: 253
Re: SAVE StringGrid to PDF
« Reply #29 on: December 14, 2024, 05:36:14 pm »
Thanks for your reply0
No line is drawn in the PDF.
On the Form there is a new little diagonal line, top left.
The code is still not correct.
 ;)

 

TinyPortal © 2005-2018