Markdown, with its simple syntax and widespread adoption among writers and developers, has emerged as a popular choice for creating structured documents. However, when it comes to sharing and printing documents, PDF remains a gold standard. From preserving formatting and layout to ensuring compatibility across platforms, this conversion process streamlines document sharing and enhances professionalism. In this article, we are going to explore the process of converting Markdown to PDF using .NET REST API, providing insights and techniques to streamline your document workflow and enhance your productivity.
MD to PDF Conversion API
With Aspose.PDF Cloud SDK for .NET, converting Markdown to PDF becomes a breeze. This powerful SDK offers a comprehensive solution for seamlessly transforming Markdown documents into professional-quality PDFs. Beyond conversion, the Cloud SDK boasts a range of exciting features to enhance your document processing capabilities. From creating PDFs from scratch to manipulating existing PDF files, adding annotations, and extracting text, this API empowers developers with versatile tools to streamline their document workflows.
In order to use the SDK, search Aspose.Pdf-Cloud
in NuGet packages manager and click the Add Package
button. This will add the SDK reference in your project.
- Obtain your client credentials from cloud dashboard. If you do not have an existing account, simply create a free account by following the instructions specified in the quick start article.
Markdown to PDF in C# .NET
As we have discovered that Aspose.PDF Cloud SDK for .NET is an ideal choice for all your PDF processing needs, so let’s use this API to convert Markdown to PDF using C# .NET. Please follow the instructions specified below to fulfill MD to PDF conversion.
PdfApi pdfApi = new PdfApi(clientSecret, clientID);
Create an object of PdfApi class where we pass client credentials as arguments.
pdfApi.UploadFile("mixed.md", stream);
Upload the input Markdown file to cloud storage.
var resltant = pdfApi.GetMarkdownInStorageToPdf(inputFile);
Call API to convert the Markdown file available in cloud storage to PDF format.
saveToDisk(resltant, "myResultant.pdf");
Custom method to save the resultant PDF to local drive.
The sample XPS file and the resultant PDF generated in above example can be downloaded from mixed.md and resultant.pdf
- In order to view the resultant PDF, you may consider using our free online PDF Viewer application.
Convert Markdown to PDF using cURL Commands
By leveraging the power of Aspose.PDF Cloud API and integrating it with cURL commands, you can easily automate the conversion process and incorporate it into your workflows. With just a few simple commands, you can initiate the conversion by specifying the input Markdown file, and receive the resulting PDF output. This approach is not only efficient but also versatile, allowing an easy integration into various development environments and platforms.
When using this approach, the first step is to generate a JWT access token using the following command:
curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=163c02a1-fcaa-4f79-be54-33012487e783&client_secret=c71cfe618cc6c0944f8f96bdef9813ac" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"
Once we have a JWT token, please execute the following command to convert Markdown file available in cloud storage to PDF format. The resultant PDF is stored on a local drive.
curl -v "https://api.aspose.cloud/v3.0/pdf/create/markdown?srcPath={sourceFile}" \
-X GET \
-H "accept: multipart/form-data" \
-H "authorization: Bearer {accessToken}" \
-o "resultant.pdf"
In case our requirement is to save the resultant PDF in cloud storage, then we need to execute the following command.
curl -v "https://api.aspose.cloud/v3.0/pdf/{resultantPDF}/create/markdown?srcPath={sourceFile}" \
-X PUT \
-H "accept: application/json" \
-H "authorization: Bearer {accessToken}" \
-d {}
Replace sourceFile
with the name of input Markdown file available in cloud storage, resultantPDF
with the name of resultant PDF image and, accessToken
with JWT access token generated above.
Conclusion
In conclusion, whether you prefer the comprehensive functionality and ease of integration provided by the SDK or the scriptable efficiency of cURL commands, both avenues offer efficient solutions for automating the conversion process. By empowering developers with the tools to seamlessly integrate Markdown to PDF conversion into their workflows, Aspose.PDF Cloud ensures that you can achieve the document processing goals with ease.
Useful Links
Related Articles
We highly recommend visiting the following blog posts for information on: