PDF to DOCX conversion is generating corrupt files in .NET

Hello,


I am using the trial version of GroupDocs.Conversion to convert a PDF file to DOCX. However, when I try to open the output file using MSWord, I get the popup that the file seems to corrupt. Please note that I am able to recover the file, and it seems to be perfectly fine. But, for my application, I cannot afford to have a corrupt file generated. Furthermore, when I convert from PDF to Doc, the output file also has no issues. Please find a snapshot of my code below:-

private byte[] ConvertPDFToWordXGroupDoc(byte[] bytePDF)
{
byte[] bytWordX = null;

try
{
string testPagesPath = System.Web.HttpRuntime.AppDomainAppPath + “\TestPages\”;
Stream streamPDF = new MemoryStream(bytePDF);

GroupDocs.Conversion.License license = new GroupDocs.Conversion.License();
license.SetLicense("");

ConversionConfig conversionConfig = new ConversionConfig { StoragePath = testPagesPath + “GroupDocStorage”, CachePath = testPagesPath + “GroupDocCache”, OutputPath = “GroupDocOutput” };
conversionConfig.UseCache = false;
ConversionHandler conversionHandler = new ConversionHandler(conversionConfig);

var convertedDocxStream = conversionHandler.Convert(streamPDF, new WordsSaveOptions { ConvertFileType = WordsSaveOptions.WordsFileType.Docx });

using (MemoryStream ms = new MemoryStream())
{
convertedDocxStream.CopyTo(ms);
bytWordX = ms.ToArray();
}
}
catch (Exception e)
{
Hashtable ht = new Hashtable(2);
ht.Add(“bytePDF”, bytePDF);
MethodInfo objMethod = (MethodInfo)MethodBase.GetCurrentMethod();
GlobalExceptionHandler.customExceptionHandler(e, objMethod, ht, ErrorSeverityType.Normal);
}

return bytWordX;
}

Regards,
Mohit Datta

Hi Mohit,

Thank you for giving a try to GroupDocs.Conversion for .NET API.

We are sorry to hear that you are facing such issue. Kindly share your sample file along with GroupDocs.Conversion for .NET API version details so we can reproduce this issue at our end.

Thank you for your cooperation.

Warm Regards,

Hi Muhammad,


Thanks for the prompt response. Actually I analyzed the code again and found that there was an issue from my end. GroupDocs.Conversion is working fine :slight_smile:

Regards,
Mohit Datta

Hi Mohit ,

We are glad to hear that you have manged it and resolved the issue.
If you will need any help or you will have any other questions please feel free to ask.

Warm Regards,