JSON files are commonly used to export, import, or transport data within or between the applications. JSON format requires less formatting and provides a lightweight data storage mechanism. 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 in C#.
- C# API to Convert JSON to PDF - Free Download
- Steps to Convert JSON to PDF in C#
- Save JSON Data as PDF in C#
C# JSON to PDF Converter - Free Download
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
How to Convert JSON to PDF in C#
Aspose.Cells for .NET makes it quite easier for you to convert a JSON file to PDF, which can be performed in a couple of steps. The following steps are required to save a JSON file as PDF in C# using Aspose.Cells for .NET.
- Create an Excel file.
- Load data from JSON file into the Excel sheet.
- Set additional conversion options for JSON to PDF.
- Save JSON data as PDF.
The following section demonstrates how to perform the above-mentioned steps for JSON to PDF conversion in C# code.
Save JSON as PDF in C#
The following are the steps to convert a JSON file to PDF using C#.
- Create an instance of the Workbook class.
- Select the default Worksheet from the Worksheets collection.
- Load JSON data from file using File.ReadAllText(string) method.
- Create an instance of JsonLayoutOptions and set options.
- Import data from JSON to worksheet using JsonUtility.ImportData method with reference to Worksheet object and JSON data.
- 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 in C#.
Export JSON to PDF in C# - Get a Free License
You can use Aspose.Cells for .NET without evaluation limitations using a temporary license.
In this article, you have learned how to convert JSON data to PDF via C#. The steps and code sample have demonstrated how to load the JSON data and save it as PDF dynamically in C#. You can use the provided code sample within your .NET, .NET Core, Mono or Xamarin based applications.