Blog


Most Recent Post  |  Next Post  |  Previous Post  |  Index List

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

Bookmarks: 

Wednesday, July 03, 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;
var
  fn: string;
  o: TTMSFNCPDFIOExportObjectArray;
  r: TTMSFNCPDFIOExportRectArray;
  ms: TMemoryStream;
begin
  {$IFDEF ANDROID}
  fn := TPath.GetSharedDocumentsPath + PathDelim + 'BMI.pdf';
  {$ENDIF}
  {$IFDEF MACOS}
  fn := TPath.GetDocumentsPath + PathDelim + 'BMI.pdf';
  {$ENDIF}
  {$IFNDEF ANDROID}
  {$IFNDEF MACOS}
  fn := 'BMI.pdf';
  {$ENDIF}
  {$ENDIF}
  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;
  try
    p.Save(ms, o, r);
    ms.SaveToFile(fn);
    {$IFNDEF WEBLIB}
    TTMSFNCUtils.OpenFile(fn);
    {$ENDIF}
  finally
    ms.Free;
  end;
end;
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!
https://download.tmssoftware.com/tmsweb/demos/TMSWeb_FNCPDFLib_BMI/

Pieter Scheldeman


Bookmarks: 

This blog post has received 5 comments. Add a comment.




Most Recent Post  |  Next Post  |  Previous Post  |  Index List