PDF to Word and Word to PDF in C# .NET

PDF to Word
pdf to word online

Microsoft Word including (DOCX, DOC, DOT, DOTX, DOTM, FlatOPC (XML) as well as OpenOffice (ODT, OTT) are among the popular office document processing/management formats. The support for rich text, document structuring, large blocks of text, page breaks, page numbering, and hidden text, are among the exciting features which compel the users to select this particular format. Similarly, Portable Document Format (PDF) is also a leading document format used for data/information sharing. So you may stumble upon a requirement to edit a PDF file and again render the output in PDF. Or, for long-term document archival, you need to convert Doc to PDF format. So in this article, we are going to discuss the details for developing a word to PDF converter.

Table Of Contents

PDF to Word Conversion API

Aspose.Words Cloud is one of our leading products which provides the feature to create as well as programmatically manipulate MS Word files. It also offers the feature to render output files in PDF/A, XPS, PS, JPEG, PNG, BMP, SVG, TIFF, EMF, PCL, SWF, CGM, HTML, etc. For more information related to supported formats, please visit document conversion. Now before we proceed with document conversion, we need to obtain a Client ID and Client Secret details from Aspose.Cloud Dashboard. For more information, you may visit Obtaining client ID and Client Secret.

Word to PDF in C#

The conversion of an MS Word file to PDF can be accomplished using a couple of code lines.

Load and save files locally

The following code snippets show the steps to load an MS Word document from a local drive and save it as a PDF.

  • Create an object of WordsApi class while passing Client ID and Client Secret as arguments
  • Create an object of ConvertDocumentRequest and provide input file path resultant output format as arguments
  • Call the ConvertDocument(..) method of WordsApi to perform the conversion

DOC to PDF in Cloud Storage

Given below are the steps describing how to upload an MS Word file from the local system into Cloud storage. Then we perform the conversion operation to PDF format. After a successful conversion, the resultant file is also saved in the same storage.

  • Create an object of WordsApi class while passing Client ID and Client Secret as arguments
  • Load MS Word file from the local system and provide it as an argument to UploadFileRequest(..) instance
  • Create an instance of SaveOptionsData where we define the format as well as the name of the resultant file
  • Create an instance of SaveAsRequest class where input Word document (uploaded earlier) and SaveOptionsData information are provided as an argument
  • Call SaveAs(..) method of WordsApi class to initialize the conversion

PDF to Word in C#

We have a separate API named Apsose.PDF Cloud which provides the features to create and manipulate as well as is also capable of converting PDF files to DOC/DOCX, etc, and other supported formats. However, if you only need to perform PDF to DOC conversion and perform other PDF file manipulation operations, then Aspose.PDF Cloud is a perfect choice. Whereas, if your main work resides with MS Word file manipulation and you also need to perform PDF to DOC conversion, then Aspose.Words Cloud is a perfect choice.

Convert PDF to Word using cURL Commands

The command below shows how to get the JWT token as per your Client ID and Client Secret.

curl -v "https://api.aspose.cloud/oauth2/token" \
-X POST \
-d "grant_type=client_credentials&client_id=xxxx-xxx-xxx-xxx&client_secret=xxxxxx" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"

The following cURL command can be used to perform PDF to Word conversion over command prompt/console.
curl -X PUT "https://api.aspose.cloud/v4.0/words/destStoredInCloud.pdf/saveAs" \
-H "accept: application/json" \
-H "Authorization: Bearer <JWT Token>" \
-H "Content-Type: application/json" \
-d "{\"SaveFormat\":\"docx\",\"FileName\":\"myResultant.docx\",\"UpdateLastSavedTimeProperty\":true,\"UpdateSdtContent\":true,\"UpdateFields\":true,\"Dml3DEffectsRenderingMode\":\"Basic\",\"UpdateLastPrintedProperty\":true}"

Conclusion

In this article, we have explored the possibilities of converting PDF to Word as well as Word to PDF using Cloud APIs. The complete source code of APIs can be downloaded from GitHub. In case you encounter any issues, please feel free to contact us via free support forums.

Related Articles

It is highly recommended to visit the following links to learn more about: