All Blog Posts  |  Next Post  |  Previous Post

Ate too much candy? Calculate and export your BMI to PDF with FNC for the WEB!


Wednesday, July 3, 2019

Ate too much candy?

We all have those moments in life where we are proud of what we have achieved, be it in sports, school, at work... . Whenever we have reached a goal, were hard work lies at the base of it, we tend to reward ourselves with something that makes us even more excited of what we have achieved. For me, that something is candy. I know, I should be eating less of it, but hey!, I have earned it! As I'm obviously eating too much of it, I created a BMI calculation app to track if I should stop eating, or if there is still room for one tiny sweet piece of candy.

FNC for the web!

The application, which calculates the BMI, is written with the help of TMS FNC UI Pack, TMS FNC Dashboard Pack and TMS WEB Core and is running in the webbrowser. It allows entering your name, height (cm) and your weight (kg). The calculate button will indicate your BMI in the grid, allowing you to know if you should loose or gain some weight, or if you are absolutely perfect.

PDF for the web!

The BMI application is allowing you to export your data to PDF. Typically, when generating a report, invoice, or any other PDF data file in the browser, this is done on a back end server. The costs to handle the load, scalability can quickly rise and the maintenance gives a lot of headaches. With the TTMSFNCPDFLib and TTMSFNCGraphicsPDFIO components that are both used in the BMI application you no longer need a backend to generate a PDF in your web application. The components completely generate the PDF at the client-side (front end).

The TTMSFNCPDFLib component is used to generate the PDF, and the TTMSFNCGraphicsPDFIO component is a bridge to export FNC UI controls such as the TTMSFNCPlanner, TTMSFNCGrid, TTMSFNCChart and many more. In the BMI web application, both are used to combine the custom PDF exporting capabilities with the TTMSFNCGrid and TTMSFNCWidgetGauge components.

The code behind this is actually very simple.
procedure TPDFLibBMILogic.GeneratePDF;
  fn: string;
  o: TTMSFNCPDFIOExportObjectArray;
  r: TTMSFNCPDFIOExportRectArray;
  ms: TMemoryStream;
  fn := TPath.GetSharedDocumentsPath + PathDelim + 'BMI.pdf';
  fn := TPath.GetDocumentsPath + PathDelim + 'BMI.pdf';
  fn := 'BMI.pdf';
  p.Options.Header := 'BMI Report for ' + FName;
  SetLength(o, 2);
  o[0] := FGauge;
  o[1] := FGrid;
  SetLength(r, 2);
  r[0] := RectF(50, 180, 50 + FGauge.Width, 180 + FGauge.Height);
  r[1] := RectF(50 + FGauge.Width + 50, 180, 50 + FGauge.Width + 50 + FGrid.Width, 180 + FGrid.Height);
  ms := TMemoryStream.Create;
    p.Save(ms, o, r);
The result, when clicking on the "Export To PDF" button, is shown below

Play with the demo yourself!

Curious on how the demo works, or if you want to know if you can eat more candy? Below is a link that shows the demo live! Note that the components, demo is currently not yet released, but we are working hard on a beta of FNC that is coming real soon, so stay tuned!

Pieter Scheldeman


This blog post has received 9 comments.

1. Thursday, July 4, 2019 at 12:12:43 AM

perfect solution, very helpful, but please make examples on other topics than bmi calc ;-)

thanks to bruno and his team


Klemt Holger

2. Thursday, July 4, 2019 at 9:34:17 AM

Sorry Holger :)

Bruno Fierens

3. Thursday, July 4, 2019 at 3:34:46 PM

Amazing stuff.. congratulations to the team for such an excellent product. The TMS components make eating candy, much too easy, lol!

Kamran Rana

4. Thursday, July 4, 2019 at 7:40:42 PM

Thanks Rana! Really appreciated!

Pieter Scheldeman

5. Sunday, July 14, 2019 at 9:09:19 PM

I like to see more samples (online or for download)
Thats very good post


6. Sunday, November 17, 2019 at 11:19:52 PM

Hello! Could explain better:

p.Options.Header := ''BMI Report for '' + FName;


7. Thursday, February 13, 2020 at 9:03:08 PM

This sets the header text of the PDF that is generated. You can see this title in the screenshot

Bruno Fierens

8. Friday, March 26, 2021 at 2:19:14 PM

I couldn''t get this example to run. I have a license for all components, but no compilation will give an error.


9. Friday, March 26, 2021 at 2:25:01 PM

For technical support:

Bruno Fierens

Add a new comment

You will receive a confirmation mail with a link to validate your comment, please use a valid email address.
All fields are required.

All Blog Posts  |  Next Post  |  Previous Post