This topic discusses how to convert a PDF to Base64 in C#. It provides the setup instructions, ordered steps, and a code example to transform a PDF to Base 64 in C#. Moreover, you can use different classes and methods to adjust the PDF rendering workflow as per your needs.
Steps to Render PDF to Base64 in C#
- Configure the system with Aspose.PDF to transform PDF to Base64 format
- Parse the PDF file with the Document class to render it to base64 encoding
- Create a MemoryStream and a ByteArray with PDF content using the ToBase64String method
- Convert the array to a Base64 string and get the result
These instructions simplify the algorithm to convert PDF file to base64 in C#. At the same time, you can enhance it further, such as reading the PDF file from an input stream, processing only selected pages, or applying other custom settings. Also, you may retrieve the output as a Base64 encoded string or even as an image.
Code to Convert PDF to Base64 in C#
The provided code snippet illustrates how to convert PDF to base 64 in C#. Simply load the PDF file and encode it into base64 using a memory stream. Afterwards, you can access the generated Base64 string either on the console or store it in a file, depending on your requirements.
This article summarizes how to convert PDF to base64 in C#. On the other hand, if you are looking for the reverse operation, then check out the article on Convert Base64 to PDF in C#.