Recent

Author Topic: Using vector graphics in FPReport  (Read 2821 times)

Pique7

  • New member
  • *
  • Posts: 9
Using vector graphics in FPReport
« on: August 13, 2022, 05:51:55 pm »
Hello, I have the ambitious aim to insert a vector graphic (WMF, EMF, EPS, SVG, PDF, ...) into a TFPReport.
The print quality should be very good, as well as the export to a PDF file.
What approach do you suggest?
Thanks in advance!

Handoko

  • Hero Member
  • *****
  • Posts: 5122
  • My goal: build my own game engine using Lazarus
Re: Using vector graphics in FPReport
« Reply #1 on: August 13, 2022, 06:15:36 pm »
Hello Pique7,
Welcome to the forum.

In the link below, you can find a list of available graphics libraries for use in Lazarus:
https://wiki.lazarus.freepascal.org/Graphics_libraries

I can't tell you which one is suitable for your case, I haven't tried them.

Pique7

  • New member
  • *
  • Posts: 9
Re: Using vector graphics in FPReport
« Reply #2 on: August 14, 2022, 06:18:56 pm »
Hello Pique7,
Welcome to the forum.
Thank you.

In the link below, you can find a list of available graphics libraries for use in Lazarus:
https://wiki.lazarus.freepascal.org/Graphics_libraries

I can't tell you which one is suitable for your case, I haven't tried them.
Thanks for your quick reply. Unfortunately none of the mentioned libraries (at least as far as I can judge) is able to fulfill the task(s) out of the box. BGRABitmap might be qualified for it.

In the meantime the cairocanvas package crossed my way. Actually I was looking for something like this, but it needs all these external libraries/DLLs.

BobDog

  • Sr. Member
  • ****
  • Posts: 394
Re: Using vector graphics in FPReport
« Reply #3 on: August 14, 2022, 07:01:09 pm »

Only one dll needed for cairo.
Two at most for cairo to freepascal, you'll need a working graphics screen also.
I'll put something together.

Pique7

  • New member
  • *
  • Posts: 9
Re: Using vector graphics in FPReport
« Reply #4 on: August 14, 2022, 07:33:02 pm »
Only one dll needed for cairo.
OK. I just tried to run the example program in the cairocanvas folder. It depends on 15 to 20 DLLs (listed in the README file). I don't know which of them are really neccessary for my case.
Actually I want to ...
  • ... load a vector graphic image from a file,
  • ... insert it into a PDF
  • ... and print it out (on a real printer).

you'll need a working graphics screen also.
The final application is intented to be a "normal" desktop GUI program, running under MS Windows (64-bit), maybe also Linux.

BobDog

  • Sr. Member
  • ****
  • Posts: 394
Re: Using vector graphics in FPReport
« Reply #5 on: August 14, 2022, 11:49:50 pm »
This is a compact dll to start with.
https://preshing.com/20170529/heres-a-standalone-cairo-dll-for-windows/
You'll notice that if you get the exports (use gendef maybe to get cairo.def), they are pretty comprehensive including pdf routines.

Code: Pascal  [Select][+][-]
  1.  
  2. function cairo_version_string() :pchar cdecl external 'cairo.dll' name 'cairo_version_string';
  3.  
  4.  
  5. begin
  6. writeln(cairo_version_string());
  7. readln;
  8. end.
  9.  

I get
1.17.2
for the 64 bit dll.
(Keep the dll with the running code)

« Last Edit: August 14, 2022, 11:54:48 pm by BobDog »

Pique7

  • New member
  • *
  • Posts: 9
Re: Using vector graphics in FPReport
« Reply #6 on: August 15, 2022, 08:11:00 am »
This is a compact dll to start with.
https://preshing.com/20170529/heres-a-standalone-cairo-dll-for-windows/
Thanks for that. I haven't testet it yet, but I assume that all the other DLLs will not be neccessary anymore.

But: I have not realized straight away that Cairo itself is not able to import/load/read/draw existing vector graphic files. Any tenable solution for this?

Pique7

  • New member
  • *
  • Posts: 9
Re: Using vector graphics in FPReport
« Reply #7 on: August 23, 2022, 06:01:02 pm »
Hello again,

I have finally managed it to load a vector graphic image from a SVG file and draw it within a TPDFDocument object using librsvg + cairo. But it is quite a handicraft work, not the most elegant solution in my opinion. I had to derive several classes from the fpPDF unit and misuse the existent construct which obviously has been initially designed for rastered image graphics. Also about 30 DLLs have accumulated meanwhile just for this purpose. Because of the necessity of librsvg in addition to cairo, I can't use BobDog's Cairo-DLL anymore.

I haven't tried to implement a corresponding FPReport component yet, but I expect a similar chaos ...

HeavyUser

  • Sr. Member
  • ****
  • Posts: 397
Re: Using vector graphics in FPReport
« Reply #8 on: August 23, 2022, 06:56:30 pm »
Hello again,

I have finally managed it to load a vector graphic image from a SVG file and draw it within a TPDFDocument object using librsvg + cairo. But it is quite a handicraft work, not the most elegant solution in my opinion. I had to derive several classes from the fpPDF unit and misuse the existent construct which obviously has been initially designed for rastered image graphics. Also about 30 DLLs have accumulated meanwhile just for this purpose. Because of the necessity of librsvg in addition to cairo, I can't use BobDog's Cairo-DLL anymore.

I haven't tried to implement a corresponding FPReport component yet, but I expect a similar chaos ...
How about converting the svg to pdf and importing that instead? After all pdf is a vector format.

Pique7

  • New member
  • *
  • Posts: 9
Re: Using vector graphics in FPReport
« Reply #9 on: August 23, 2022, 07:38:29 pm »
How about converting the svg to pdf and importing that instead? After all pdf is a vector format.
I would say, principally I have done exactly this, but including the conversion procedure in my program instead of doing it in advance.
As I mentioned already, I don't believe my work to be a solid, universal solution. The import procedure works with simple SVG files converted by librsvg+cairo, because it is more or less predictable how the resulting PDF stream will look like. I don't know how I should import any arbitrary PDF. Perhaps it is possible, but I haven't found a way.

Pique7

  • New member
  • *
  • Posts: 9
Re: Using vector graphics in FPReport
« Reply #10 on: August 30, 2022, 05:05:25 pm »
So, the deed is done. At least, I believe this.

It's not straightforward, it's not beautiful, it's not convenient, but at least ... it seems to be possible (for SVG images).

I've just used it in a simple test program so far. Unforeseen troubles cannot be ruled out in more complicated applications.

 

TinyPortal © 2005-2018