Articles in this section
Category / Section

How to draw the Euro symbol in a PDF in UWP

2 mins read

Syncfusion Essential PDF is the UWP PDF library used to create, read, and edit PDF documents. Using this library, you can draw the Euro symbol by using suitable TrueType font in UWP platform.

Steps to draw the Euro symbol to PDF document programmatically:

  1. Create a new UWP application project. euroSymbolSample
  2. Install the Syncfusion.Pdf.UWP NuGet package as reference to your UWP applications from NuGet.org. Install required Nuget packages
  3. In the MainPage.xaml, add a new button as follows.
    <Page
        x:Class="EuroSymbolSample.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:EuroSymbolSample"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
     
        <Grid>
            <Button x:Name="btn1" Content="Generate PDF" Click="OnButtonClick" VerticalAlignment="Center" HorizontalAlignment="Center"></Button>
        </Grid>
    </Page>
    

 

  1. Include the following namespaces in the MainPage.xaml.cs file.
    using Syncfusion.Pdf;
    using Syncfusion.Pdf.Graphics;
    

 

  1. Add the suitable font file to the Assert folder and set the Build Action to Embedded Resource. buildaction
  2. Include the following code snippet in the click event of the button in MainPage.xaml.cs to draw the EURO symbols to the PDF document and save it in a stream.
    //Create a new PDF document
    PdfDocument doc = new PdfDocument();
     
    //Adds new page
    PdfPage page = doc.Pages.Add();
     
    //Get the font file as stream
    Stream fontStream = typeof(MainPage).GetTypeInfo().Assembly.GetManifestResourceStream("EuroSymbolSample.Assets.arial.ttf");
     
    //Create a new PdfTrueType font instance
    PdfTrueTypeFont font = new PdfTrueTypeFont(fontStream, 14);
     
    //Draw the EURO symbol
    page.Graphics.DrawString("€ $ ¥", font, PdfBrushes.Black, new PointF(0, 0));
     
    MemoryStream stream = new MemoryStream();
     
    //Save the document
    doc.Save(stream);
     
    //Close the document
    doc.Close(true);
     
    //Save the PDF stream to physical file
    Save(stream, "output.pdf");
    

      

  1. Use the following helper method to save the stream as a physical file and open the file for viewing.
    #region Helper Methods
    public async void Save(Stream stream, string filename)
            {
                stream.Position = 0;
                StorageFile stFile;
                if (!(Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons")))
                {
                    FileSavePicker savePicker = new FileSavePicker();
                    savePicker.DefaultFileExtension = ".pdf";
                    savePicker.SuggestedFileName = "Output";
                    savePicker.FileTypeChoices.Add("Adobe PDF Document", new List<string>() { ".pdf" });
                    stFile = await savePicker.PickSaveFileAsync();
                }
                else
                {
                    StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
                    stFile = await local.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting);
                }
                if (stFile != null)
                {
                    Windows.Storage.Streams.IRandomAccessStream fileStream = await stFile.OpenAsync(FileAccessMode.ReadWrite);
                    Stream st = fileStream.AsStreamForWrite();
                    st.Write((stream as MemoryStream).ToArray(), 0, (int)stream.Length);
                    st.Flush();
                    st.Dispose();
                    fileStream.Dispose();
                    MessageDialog msgDialog = new MessageDialog("Do you want to view the Document?", "File created.");
                    UICommand yesCmd = new UICommand("Yes");
                    msgDialog.Commands.Add(yesCmd);
                    UICommand noCmd = new UICommand("No");
                    msgDialog.Commands.Add(noCmd);
                    IUICommand cmd = await msgDialog.ShowAsync();
                    if (cmd == yesCmd)
                    {
                        // Launch the retrieved file
                        bool success = await Windows.System.Launcher.LaunchFileAsync(stFile);
                    }
                }
            }
    #endregion
    

 

By executing the program, you will get the PDF document as follows. output-euro

A complete working sample can be downloaded from EuroSymbolSample.zip

Take a moment to peruse the documentation, where you can find other options like drawing Unicode text,  RTL text, and Complex script language text to the PDF document.

Refer here to explore the rich set of Syncfusion Essential PDF features.

Note:

Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to link to learn about generating and registering Syncfusion license key in your application to use the components without trail message.

 

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied