FPPDF Trouble with setting font colours lazarus / 21-General ---------------------------------------------------------------------- tdb · 2024-10-27 03:30 Starting to use FPPDF to create reports and so far most works very well, however I have an issue setting the font colour. See code extract below PDF gets created but all use text is Black So far I have tried - 1. Prefixing the clColor codes with FPPDF i.e. FpPdf.clGreen no affect. 2. Placed the FPPDF library first in the uses list - No affect. 3. Try using HEX colour code directly i.e. SetColor($800000) - No affect. Must be something basic I have missed, But what? Any help would be greatly appreciated as I am at a complete loss as to how to fix. I can provide a complete test project that shows the issue.   // Output out some text in Black   oPage.SetColor(fppdf.clBlack, True);   oPage.WriteText(30, 40, 'Some text in Black.');   // Output out some text in Green   oPage.SetColor(fppdf.clGreen, True);   oPage.WriteText(30, 60, 'Some more text in Green.');   // Output out some text in Red   oPage.SetColor(fppdf.clRed, True);   oPage.WriteText(30, 80, 'Some more text in Red.');   // Output out last line in Maroon   oPage.SetColor($800000, True);   oPage.WriteText(30, 100, 'Set colour using Hex from FPPDF $800000 (Maroon).'); ---------------------------------------------------------------------- paweld · 2024-10-27 06:16 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 RGBToBGR(color: TColor): TColor;var  r, g, b: Byte;begin  RedGreenBlue(color, r, g, b);  Result := RGBToColor(b, g, r);end;   // Output out some text in Black  oPage.SetColor(clBlack, False);  oPage.WriteText(30, 40, 'Some text in Black.');   // Output out some text in Green  oPage.SetColor(clGreen, False);  oPage.WriteText(30, 60, 'Some more text in Green.');   // Output out some text in Red  oPage.SetColor(RGBToBGR(clRed), False);  oPage.WriteText(30, 80, 'Some more text in Red.');   // Output out last line in Maroon  oPage.SetColor(RGBToBGR($800000), False);  oPage.WriteText(30, 100, 'Set colour using Hex from FPPDF $800000 (Maroon).');Attached is a sample project ---------------------------------------------------------------------- tdb · 2024-10-27 10:10 First off thank you for your reply. I tried your function code it made no difference still black - here is my modified code. I did not think this would work as I have already passed the colours in FpPdf colour format (Cardinal) and not in native Lazarus TColor also tried Hex as in the original post.   // Output out some text in Black //  oPage.SetColor(fppdf.clBlack, True);   oPage.SetColor(RGBToBGR(clBlack), True);   oPage.WriteText(30, 40, 'Some text in Black.');   // Output out some text in Green //  oPage.SetColor(fppdf.clGreen, True);   oPage.SetColor(RGBToBGR(clGreen), True);   oPage.WriteText(30, 60, 'Some more text in Green.');   // Output out some text in Red //  oPage.SetColor(fppdf.clRed, True);   oPage.SetColor(RGBToBGR(clRed), True);   oPage.WriteText(30, 80, 'Some more text in Red.');   // Output out last line in Maroon //  oPage.SetColor($800000, True);   oPage.SetColor(RGBToBGR($800000), True);   oPage.WriteText(30, 100, 'Set colour using Hex from FPPDF $800000 (Maroon).'); ---------------------------------------------------------------------- paweld · 2024-10-27 10:35 When setting the color with SetColor, you must pass False as the second parameter - only then will the color for the text be set. And the function is needed because fppdf expects color in BGR format, not RBG, at least in FPC 3.2-fixes. ---------------------------------------------------------------------- dbannon · 2024-10-27 11:19 tdb, what version of FPC are you using ? There were changes in fppdf between fpc3.2.2 and the current fpc3.2.4 rc1. As paweld said, all our tests done in a recent session with fpcpdf used false as that second parameter. Apparently is something about 'stroked and nonstroked fonts, does not seem relevant in a ttf world but we did use false and it did produce the expected colors. I have just noted that I have removed the colored heading from the PDF maker in my app. I will have to look into that, it could be because it will not work with FPC3.2.2 (and I have to use 3.2.2 on official Debian packages). And it may be that Lazarus clColor does not work, you must use the FPC colors. fpcpdf is a FPC component, not a Lazarus one. Attached is a demo we played with while trying to make Chinese characters, it definitely prints some blue text on my FPC3.2.3 system. It does not show a GUI, just starts up, makes a pdf and exists. See if it works for you. Davo ---------------------------------------------------------------------- tdb · 2024-10-28 03:23 Thank you "paweld" so much you are correct passing the 2nd parameter as False worked. So simple don't know why I did not try that. One thing I would note is that if you prefix the colours with pfpdf then it uses the colour codes built into fppdf i.e. I use fppdf.clGreen That way no need to convert first. Once again thank you. ---------------------------------------------------------------------- tdb · 2024-10-28 03:36 Quotetdb, what version of FPC are you using ? There were changes in fppdf between fpc3.2.2 and the current fpc3.2.4 rc1. As paweld said, all our tests done in a recent session with fpcpdf used false as that second parameter. Apparently is something about 'stroked and nonstroked fonts, does not seem relevant in a ttf world but we did use false and it did produce the expected colors. I have just noted that I have removed the colored heading from the PDF maker in my app. I will have to look into that, it could be because it will not work with FPC3.2.2 (and I have to use 3.2.2 on official Debian packages). And it may be that Lazarus clColor does not work, you must use the FPC colors. fpcpdf is a FPC component, not a Lazarus one. Attached is a demo we played with while trying to make Chinese characters, it definitely prints some blue text on my FPC3.2.3 system. It does not show a GUI, just starts up, makes a pdf and exists. See if it works for you. Davo Davo, thank you for your reply. Not sure what version of fppdf I am using - is there a way to find out? I opened the source .pas file but no mention of version number - I believe I am using 3.2.2 If there is a later version I should download as I have noticed the font width functions seem to be incorrect which mays right justifying text hard. For anyone that is interested fppdf makes a great alternative report writer with a bit of effect it work great. I tried the others report writers available but all had issues. Being an oldie I was use to code reports the long way and while harder gives nearly complete control. So far this seems to work well the reports are very fast and relatively easy to program. Once you have the skeleton report you can reuse over and over. tdb ---------------------------------------------------------------------- paweld · 2024-10-28 06:29 Quote from: tdbOne thing I would note is that if you prefix the colours with pfpdf then it uses the colour codes built into fppdf i.e. I use fppdf.clGreen That way no need to convert first.thank you for the information - I didn't know @tdb: If you're creating reports based on some data, I recommend LazReport, which has, among other things, the ability to export to PDF using fcl-pdf. The report designer is a very big help when creating reports ---------------------------------------------------------------------- dbannon · 2024-10-28 07:07 Quote from: tdb on October 28, 2024, 04:36:49 amNot sure what version of fppdf I am using - is there a way to find out? I opened the source .pas file but no mention of version number - I believe I am using 3.2.2 fpcpdf comes with the FPC compiler, unless you have updated it, manually, its very, very likely you are using FPC322. An update to FPC, perhaps to the current release candidate will get you the new version, it is substantially better. Possibly, better with what you are doing. But its not quite as easy as you might expect. You need to download the source and compile it, address the config issues and set some PATH. Without knowing your operating system, I cannot be more explicit. It might be possible to download just the fpcpdf and libfontconfig unit files (from gitlab), I'd think there is a good chance they would work with the old compiler but not sure. So, what OS are you using and how brave do you feel ? Davo ---------------------------------------------------------------------- tdb · 2024-10-28 09:55 Quote from: paweld on October 28, 2024, 07:29:37 am@tdb: If you're creating reports based on some data, I recommend LazReport, which has, among other things, the ability to export to PDF using fcl-pdf. The report designer is a very big help when creating reports I did try LazReport but had some issues can't remember what, anyway very happy with fppdf it is easy to use as a report writer like tool. Built a small class to help make it quicker to setup a report. Personally I like having full control of the reports I created and lastly runs very fast. ---------------------------------------------------------------------- tdb · 2024-10-28 10:13 Quote from: dbannon on October 28, 2024, 08:07:36 amAn update to FPC, perhaps to the current release candidate will get you the new version, it is substantially better. Possibly, better with what you are doing. But its not quite as easy as you might expect. You need to download the source and compile it, address the config issues and set some PATH. Without knowing your operating system, I cannot be more explicit. It might be possible to download just the fpcpdf and libfontconfig unit files (from gitlab), I'd think there is a good chance they would work with the old compiler but not sure. So, what OS are you using and how brave do you feel ? Davo Not sure I am that brave looking at the Lazarus home page I see release candidate of Lazarus 4.0 showing built with FPC 3.2.2 not 3.4.x So while I would like to try the latest version of fppdf without a guide or "how to" I think I will wait for the Lazarus team to do their thing. On the other hand if you can link me a guide/how to I will backup and give it a try! Either way I have most of what I need for the moment, only things that would be nice are the Font Width calculations to be fixed. Anyway thanks Davo for your help - its good to know if you have issues there are people on the forum that will help. ---------------------------------------------------------------------- tdb · 2024-10-28 10:19 Quote from: dbannon on October 28, 2024, 08:07:36 amWithout knowing your operating system, I cannot be more explicit. Davo Forgot to mention Windows 10 + Lazarus 3.2.2 using Zeos and Firebird seems to work well. I have noticed some issues with the IDE mostly fixable. ---------------------------------------------------------------------- dbannon · 2024-10-28 10:44 OK, I am not a good one to help you on Windows I am afraid. I can do it on my Windows test box but I'd not feel confident, remotely. Must be some real windows users here. As a Windows user, you might be a bit less comfortable doing whats necessary too I am afraid. FPC_3_2_4_RC_1 does build Lazarus 4.0 quite reliably. I'd not recommend 3.2.3 due to some issues discussed in another thread. Good luck with your project ! Davo