Recently Aberfeldie Masters Athletics ran a 1 Hour Track Run. This project was created to dynamically generate certificates for participants and email them along with the event results. It is being made extensible so that it could be used for a variety of athletics running events.



Discussion

A spreadsheet was used to present the event results with the folowing columns

  • Number
  • Name
  • Email
  • Distance
  • Time

Time was not used except for some competitors who finished earlier and one who made a late start. So there are two versions of the certification, the second including time.

A Powershell script was created to read the spreadsheet and iterate through allathletes listed. Before iterating it gnerated a list of results for all as pdf file that is included when the certificates are sent. The certificates are generated with fixed data such as the heading and labels, and an image for the event as well as specific data for each athlete:

  • Name
  • Distance

For competitors with a time, a second template was used:

  • Name
  • Distance
  • Time

The Scripts

Some Specifications

$SendUsingAccount = "account@location.com.au"

$ExcelFile = Join-Path $RootFolder "Resultsentrants-aberfeldie-one-hour-track-challenge.xlsx"
$TemplateFile = Join-Path $RootFolder "CertificateTemplate.png"

$PngFolder = Join-Path $RootFolder "Output\PNG"
$ResultsFolder = Join-Path $RootFolder "Results"

$ResultsXlsx = Join-Path $ResultsFolder "OfficialResults.xlsx"
$ResultsPdf = Join-Path $ResultsFolder "Aberfeldie-1-Hour-Track-Run-Results-2026.pdf"

Background Image

This is starts with the $TemplateFile image as specified above. This was generated starting with an image of the certificate as discussed in this post coming

    $Bitmap = New-Object System.Drawing.Bitmap $TemplateFile
    $Graphics = [System.Drawing.Graphics]::FromImage($Bitmap)
    $Graphics.SmoothingMode =
        [System.Drawing.Drawing2D.SmoothingMode]::HighQuality

Text inserted as in Add Text the Graphics

    $SafeName = $Name -replace '[\\/:*?"<>|]', ''

    $CertificateFile = Join-Path $PngFolder (
        "{0:D3}-{1}.png" -f [int]$Number, $SafeName
    )

    $Bitmap.Save(
        $CertificateFile,
        [System.Drawing.Imaging.ImageFormat]::Png
    )

    $Graphics.Dispose()
    $Bitmap.Dispose()

$CertificateFile is what is sent for each individual.

Add Text to the Graphics

In the original verion of the script/s some generic text such as the event bane, were embedded in the image. The Powershell script then placed the inserted text using

    $NameY          = 1150  # Adjusted to fit
    $DistanceY      = 1380

    $NameSize = $Graphics.MeasureString($Name, $NameFont)
    $NameX = ($Bitmap.Width - $NameSize.Width) / 2

    $DistanceSize = $Graphics.MeasureString($DistanceText, $DistanceFont)
    $DistanceX = ($Bitmap.Width - $DistanceSize.Width) / 2

Then drawing the text for name, for example:

    $Graphics.DrawString(
        $Name,
        $NameFont,
        $Brush,
        $NameX,
        $NameY
    )

For the second script and template the Name, Distance and Time labels are included in the Powershell script whereas in the other (earlier version), those labels are embedded in the image

Currently working upon removing all text from the image and having the scripts generate that.


Next


 TopicSubtopic
  Next: > Athletics Certificate Generator
<  Prev:   AI processing
   
 This Category Links 
Category:Application Dev Index:Application Dev