Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This Gist contains code snippets related to Converting PDF to Word format using C#
// get client credentials from https://dashboard.aspose.cloud/
string clientSecret = "caac6e3d4a4724b2feb53f4e460eade3";
string clientID = "4ccf1790-accc-41e9-8d18-a78dbb2ed1aa";
// create an instance of PdfApi
PdfApi pdfApi = new PdfApi(clientSecret, clientID);
// Input PDF file name
String inputFile = "HtmlExample1.pdf";
// upload the file to cloud storage
using (var file = System.IO.File.OpenRead("/Users/nshahbaz/Downloads/" +inputFile))
{
var response = pdfApi.UploadFile(inputFile, file );
}
try
{
// call the method to perform conversion and save output in stream instance
// We have specified the ouptut format as Docx and mode as Flow
// The mode value allows to control how a PDF document is converted into a word processing document.
var response = pdfApi.GetPdfInStorageToDoc(inputFile,null, format: "Docx",null,null,maxDistanceBetweenTextLines: 2,mode: "Flow", folder: null);
Console.WriteLine(response);
// call method to save output on local drive
saveToDisk(response, "/Users/nshahbaz/Downloads/Converted.docx");
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace);
}
// method to save stream content to file on local drive
public static void saveToDisk(Stream responseStream, String resultantFile)
{
var fileStream = File.Create(resultantFile);
responseStream.Seek(0, SeekOrigin.Begin);
responseStream.CopyTo(fileStream);
fileStream.Close();
}
This Gist contains code snippets related to Converting PDF to Word format using C#
// get client credentials from https://dashboard.aspose.cloud/
string clientSecret = "caac6e3d4a4724b2feb53f4e460eade3";
string clientID = "4ccf1790-accc-41e9-8d18-a78dbb2ed1aa";
// create an instance of PdfApi
PdfApi pdfApi = new PdfApi(clientSecret, clientID);
// Input PDF file name
String inputFile = "HtmlExample1.pdf";
// upload the file to cloud storage
using (var file = System.IO.File.OpenRead("/Users/nshahbaz/Downloads/" +inputFile))
{
var response = pdfApi.UploadFile(inputFile, file );
}
// resultant file name
string outputfile = "result.doc";
try
{
// call the method to perform conversion and save output in Cloud storage
var response = pdfApi.PutPdfInStorageToDoc(inputFile, outputfile, format: "Doc",folder: null);
// print response code in console
Console.WriteLine(response);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment