DOC to PDF in C#

doc to pdf in C#

The Portable Document Format (PDF) is one of the popular document formats for information sharing over the internet. It’s due to the amazing capabilities of preserving document formatting/fidelity when viewing on various platforms. At the same time, Word documents (DOC, DOCX, etc) are also widely used for official information storage and sharing in organizations, universities, govt institutes, etc. But the challenge with Word documents is that you need specialized applications to view them. Also, in case the fonts used inside Word documents are not installed on the system, the formatting of documents is disturbed. Owing to these constraints, one of the viable solutions is to convert the DOC files to PDF format, and in this article, we are going to discuss the conversion of DOC to PDF in C#.

Word processing API

Aspose.Words Cloud is our award-winning REST API-based MS Word, Open Office, OpenDocument, and other popular formats processing API. The details regarding the complete list of supported formats can be found over Supported File Formats. Furthermore, the API enables you to create, edit as well as convert files to other formats including PDF, XPS, SVG, PCL, JPEG and much more. Therefore, perform all the document processing operations within the cloud without MS Office automation or any other software installed. Nevertheless, in order to facilitate our customers, we have created Aspose.Words Cloud SDK for .NET which is a wrapper around Aspose.Words REST API. So you could seamlessly integrate Microsoft Word® document generation, manipulation, conversion & inspection features into your own .Net applications.

Installation

Please note that in order to get started, the first step is to install the Cloud SDK either from NuGet or GitHub. So 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.

  • Open the Solution Explorer window in VisualStudio
  • Right-click the Packages section and select Manage NuGet Packages… option
  • Search Aspose.Words-Cloud in the search field
  • Select Aspose.Words-Cloud checkbox and click Add Package button
Manage NuGet Packages
Image 1:- Manage NuGet Packages option.
Aspose.Words-Cloud NuGet Package
Image 2:- Search Aspose.Words-Cloud among NuGet package.
Aspose.Words-Cloud in Solution
Image 3:- Aspose.Words Cloud SDK for .NET in Solution.

Cloud Subscription

Our APIs are only accessible to authorized personnel only, so the first step is to register an account over Aspose.Cloud dashboard. If you have GitHub or Google account, simply Sign Up. Or, click on the Create a new Account button and provide the required information. Now login to the dashboard using credentials and expand the Applications section from the dashboard. Scroll down towards the Client Credentials section to see Client ID and Client Secret details.

Please note that under the free subscription plan, you can perform up to 150 free document processing requests. After you are convinced of the capabilities of REST APIs, you may consider opting for an account subscription for as low as $0.005 / API Call under pay as you go model. For more information, please visit the Pricing plan.

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.

  • Frist of all, create String objects defining Client ID and Client Secret details as per account
  • Secondly, create an instance of WordsApi while passing ClientSecret and ClientID details as arguments
  • Now create an instance of GetDocumentWithFormatRequest class and pass input DOC file name, resultant format and output file name as arguemnts
  • Finally, call the GetDocumentWithFormat(..) method to perform the conversion
doc to pdf in C#

Convert DOC to PDF using cURL command

Aspose.Words Cloud SDK for .NET is a programming SDK developed on top of Aspose.Words Cloud REST API. Our Cloud REST APIs can be accessed from any platform and the cURL commands are one of the easiest ways. However, in order to use APIs via cURL commands, we need to first generate a JWT access token based on Client ID and Client Secret details.

 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"

Once the JWT token has been generated, access GetDocumentWithFormat API to perform DOC to PDF conversion.

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>"
doc to pdf conversion

Conclusion

In this article, we have discussed the capabilities of Aspose.Words Cloud SDK for .NET to convert doc files to PDF format using C# code snippet and while using the cURL command. Other than conversion, the API also provides amazing features and their details can be found in the Overview section. Please note that our Cloud SDKs opensource and their complete code snippet can be found over GitHub. In case you encounter any issue while using the API or you have any related query, please feel free to contact via the Free product support forum.

Related Links

We recommend visiting the following links for information on