Convert DOC to PDF in C#

DOC to PDF
Convert DOC to PDF Online | Convert Word to PDF using C# .NET

The Portable Document Format (PDF) is one of the popular document formats for information sharing over the internet. One of the salient features is its capability of preserving document formatting/fidelity when viewed on various platforms. Similarly, Word documents (DOC, DOCX, etc) are also widely used for official information storage and sharing in organizations, universities, govt institutes, etc. but you need specialized applications to view these documents and its formating is disturbed if any custom font used in the Word documents is not installed. So in order to cater to these scenarios, we are going to learn the steps on how to convert DOC to PDF in C#.

Word to PDF Conversion API

Aspose.Words Cloud provides the feature to create, edit and transform MS Word, Open Office, OpenDocument, and other Supported File Formats. It also enables you to convert word to PDF, XPS, SVG, PCL, JPEG, and various other formats. Now in order to perform DOC to PDF conversion in C# .NET application, we need to use Aspose.Words Cloud SDK for .NET (which is a wrapper around Aspose.Words Cloud API).

Installation

The first step is to install the .NET SDK which is available for download over NuGet or GitHub. Please execute the following command in the Nuget package manager console to install the SDK.

Install-Package Aspose.Words-Cloud

Or, you can directly install the dependencies within the VisualStudio solution.

The next step is to register an account over Aspose.Cloud dashboard using GitHub or Google account or simply Sign Up to obtain your Client Credentials.

DOC to PDF in C#

Please follow the steps given below to convert DOC file already available on cloud storage to PDF conversion using C# .NET code.

  • Firstly, create an instance of WordsApi while passing ClientSecret and ClientID details as arguments
  • Then create an instance of GetDocumentWithFormatRequest class and pass the input DOC file name, resultant format, and output file name as arguments
  • Finally, call the GetDocumentWithFormat(..) method to perform the conversion
doc to pdf
Image 1:- DOC to PDF conversion preview.

Convert Word to PDF using cURL Commands

The conversion of Word to PDF can also be performed using cURL commands. So the first step is to generate a JWT access token based on Client ID and Client Secret details. Please execute the following command to generate a JWT token:

 curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=718e4235-8866-4ebe-bff4-f5a14a4b6466&client_secret=388e864b819d8b067a8b1cb625a2ea8e" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"

Now we need to access GetDocumentWithFormat API to convert Word to PDF.

curl -X GET "https://api.aspose.cloud/v4.0/words/GetStyles.doc?format=pdf&outPath=Resultant.pdf" \
-H  "accept: application/octet-stream" \
-H  "Authorization: Bearer <JWT Token>"
Word to PDF conversion preview
Image 2:- Word to PDF conversion preview.

Conclusion

In this article, we have discussed the capabilities of Aspose.Words Cloud SDK for .NET and have specifically learned how to convert doc to PDF using C# code snippet. We also have explored the option to convert word to PDF using cURL commands in the command line terminal. You may consider visiting the Overview section of the programmers’ guide to learn about other capabilities of the API.

The complete source code of Cloud SDK can be downloaded from GitHub and in case you encounter any issue while using the API, please feel free to contact us via the Free product support forum.

Related Links

We recommend visiting the following links for information on