Convert JSON to PDF using C#

JSON to PDF C#

In various cases, you may need to convert the JSON files to PDF for sharing, printing, or other purposes. To achieve it programmatically, this article covers how to convert JSON to PDF using C#.

C# API for JSON to PDF Conversion

In order to convert JSON files to PDF format, we will use Aspose.Cells for .NET. It is a powerful API that allows you to generate spreadsheet documents from scratch. In addition, it lets you process and convert existing Excel files from within your .NET applications. You can either download the API or install it using NuGet.

PM> Install-Package Aspose.Cells

Convert JSON to PDF in C#

The following are the steps to convert a JSON file to PDF using C#.

  1. Create an instance of the Workbook class.
  2. Select the default Worksheet from the Worksheets collection.
  3. Load JSON data from file using File.ReadAllText(string) method.
  4. Create an instance of JsonLayoutOptions and set options.
  5. Import data from JSON to worksheet using JsonUtility.ImportData method with reference to Worksheet object and JSON data.
  6. Convert JSON to PDF by saving the workbook as PDF using Workbook.Save(string, SaveFormat.Auto) method.

The following code sample shows how to convert a JSON file to PDF.

Get a Free License

You can use Aspose.Cells for .NET without evaluation limitations using a temporary license.

Conclusion

In this article, you have learned how to import JSON data and convert it to PDF using C#. You can use the provided code sample within your .NET, .NET Core, Mono or Xamarin based applications. In addition, you can explore the documentation of Aspose.Cells for .NET. Also, you can post your queries on our forum.

See Also