This short tutorial shows you how to convert PDF to XML with C# REST API in the cloud. In order to export PDF to XML format, we’re using Aspose.PDF for C# Cloud SDK. If you’re interested in PDF to XML Conversion in C# Low Code API then this can be achieved with the help of this sample code and steps.
Prerequisite
- Setup an account API credentials
- Download Aspose.PDF Cloud SDK for Dotnet
- Setup C# project with the above SDK
Steps to Convert PDF to XML in C# REST API
- Set the Client ID and Client Secret for the API
- Create an instance of the pdfApi class with client credentials
- Specify input and output files
- Read the input PDF file and upload it to cloud storage
- Call PutPdfInStorageToXML method to Convert PDF to XML using REST API
- Save the output XML file on the local disk
Code for PDF to XML Conversion in C# Low Code API
using System; | |
using System.IO; | |
using Aspose.Pdf.Cloud.Sdk.Api; | |
namespace Aspose.PDF.Cloud.Examples.Kb | |
{ | |
public class PdfToXml | |
{ | |
public static void ConvertPdfToXml() | |
{ | |
try | |
{ | |
PdfApi pdfApi = new PdfApi("Client Secret", "Client Id"); | |
string localPath = @"C:\Words\"; | |
string srcFileName = "Sample.pdf"; | |
string outputFile = "PDFtoXML.xml"; | |
// Upload source file to the cloud storage | |
pdfApi.UploadFile(srcFileName, File.Open(localPath + srcFileName, FileMode.Open)); | |
pdfApi.PutPdfInStorageToXml(srcFileName, outputFile); | |
// Download the output file from Cloud Storage | |
var stream = pdfApi.DownloadFile(outputFile, null, null); | |
using (var fileStream = File.Create(localPath + outputFile)) | |
{ | |
stream.Seek(0, SeekOrigin.Begin); | |
stream.CopyTo(fileStream); | |
} | |
} | |
catch (Exception ex) | |
{ | |
System.Diagnostics.Debug.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace); | |
} | |
} | |
} | |
} |
The sample code shared above empowers you to convert PDF to XML with C# REST API. You only have to input a PDF file with the help of the Aspose.PDF REST API SDK for C# and download the output XML file to save it locally by using the Aspose conversion API online.
This PDF to XML Conversion could used with any no-code or low-code apps on any device or computer. A related feature might also be helpful to you: How to Convert PDF to TIFF with C# REST API.