PDF - Format Currency and Date

Is their a way to format a column as a date and also as a currency? 

For example, how to do date and currency

        PdfStringFormat format = new PdfStringFormat();
        format.Alignment = PdfTextAlignment.Right;
        format.LineAlignment = PdfVerticalAlignment.Bottom;
(How to set as currency or date mm/dd/yyyy)

        pdfGrid.Columns[3].Format = format;


Using the following code:
 public async void PdfExport()
    {
        //Create a new PDF document
        PdfDocument doc = new PdfDocument();
        //Add a page
        PdfPage page = doc.Pages.Add();
        //Create a PdfGrid
        PdfGrid pdfGrid = new PdfGrid();
        //Add IEnumerable
        DateTime dt1 = new DateTime(2019, 06, 01);
        DateTime dt2 = new DateTime(2019, 09, 30);
        IEnumerable repqtrtransactions;
        repqtrtransactions = await M_Transactions.RepQuarterlyTrades(9, dt1, dt2);
        //Assign data source
        pdfGrid.DataSource = repqtrtransactions;

        PdfStringFormat format = new PdfStringFormat();
        format.Alignment = PdfTextAlignment.Right;
        format.LineAlignment = PdfVerticalAlignment.Bottom;
        pdfGrid.Columns[3].Format = format;


        //Apply built-in table style
        pdfGrid.ApplyBuiltinStyle(PdfGridBuiltinStyle.GridTable4Accent1);

        //Draw grid to the page of PDF document
        pdfGrid.Draw(page, new Syncfusion.Drawing.PointF(10, 10));
        //Creating the stream object
        MemoryStream stream = new MemoryStream();
        //Save the PDF document to stream.
        doc.Save(stream);
        //If the position is not set to '0' then the PDF will be empty.
        stream.Position = 0;
        //Close the document.
        doc.Close(true);
        //Defining the ContentType for pdf file.
        string contentType = "application/pdf";
        //Define the file name.
        string fileName = "Output.pdf";
        var path = "Upload/QtrReports/" + fileName;
        //You have to rewind the MemoryStream before copying
        stream.Seek(0, SeekOrigin.Begin);

        using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate))
        {
            stream.CopyTo(fs);
            fs.Flush();
        }

    }




2 Replies

SL slynch December 8, 2020 05:31 PM UTC

Okay, I think I got it. I switched my viewmodel field type to string and then formatted it the way that I wanted it to display and it worked.


GK Gowthamraj Kumar Syncfusion Team December 9, 2020 01:58 PM UTC

Hi slynch, 

Thank you for using Syncfusion products. We are glad to know that your problem has been solved.   
  
Please refer to the below link for more information,   
    
Regards, 
Gowthamraj K 


Loader.
Up arrow icon