Using vector graphics in FPReport lazarus / 5-Lazarus Extra Components ---------------------------------------------------------------------- Pique7 · 2022-08-13 15:51 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 · 2022-08-13 16:15 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 · 2022-08-14 16:18 Quote from: Handoko on August 13, 2022, 06:15:36 pmHello Pique7, Welcome to the forum. Thank you. Quote from: Handoko on August 13, 2022, 06:15:36 pmIn 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 · 2022-08-14 17:01 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 · 2022-08-14 17:33 Quote from: BobDog on August 14, 2022, 07:01:09 pmOnly 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). Quote from: BobDog on August 14, 2022, 07:01:09 pmyou'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 · 2022-08-14 21:49 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  function cairo_version_string() :pchar cdecl external 'cairo.dll' name 'cairo_v ersion_string';  beginwriteln(cairo_version_string());readln;end.  I get 1.17.2 for the 64 bit dll. (Keep the dll with the running code) ---------------------------------------------------------------------- Pique7 · 2022-08-15 06:11 Quote from: BobDog on August 14, 2022, 11:49:50 pmThis 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 · 2022-08-23 16:01 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 · 2022-08-23 16:56 Quote from: Pique7 on August 23, 2022, 06:01:02 pmHello 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 · 2022-08-23 17:38 Quote from: HeavyUser on August 23, 2022, 06:56:30 pmHow 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 · 2022-08-30 15:05 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.