Unable to save a PDF to a docx or to a stream.
Version: 22.2.0
Tech Stack: .net
While attempting to save this file to docx or to a stream the save basically stops working. No exception is thrown and it does not ever finish saving the document.
Here is a copy of the pdf file we are attempting to save as docx or to a stream
8.4.b - ZMA-00179-2023_Moore Rezone RA to IL.staff report.pdf (3.5 MB)
Here is the code I’m using to convert to docx
private Document ConvertBadDocument(Document docToAdd)
{
if (!Directory.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "temp", @"convertingBadDocument")))
{
Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "temp", @"convertingBadDocument"));
}
string tempPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "temp", @"convertingBadDocument\convertedDocument.docx");
MemoryStream streamDocx = new MemoryStream();
try
{
docToAdd.Save(tempPath, SaveFormat.DocX);
}
catch (Exception ex)
{
var test = "";
}
ELSLogHelper.InsertInfoLog(ELSLogHelper.AsposeLogMessage("Save"), MethodBase.GetCurrentMethod()?.Name, MethodBase.GetCurrentMethod().DeclaringType?.Name, Environment.StackTrace);
var docx = new wordsAspose.Document(tempPath);
ELSLogHelper.InsertInfoLog(ELSLogHelper.AsposeLogMessage("Open"), MethodBase.GetCurrentMethod()?.Name, MethodBase.GetCurrentMethod().DeclaringType?.Name, Environment.StackTrace);
MemoryStream streamPdf = new MemoryStream();
docx.Save(streamPdf, wordsAspose.SaveFormat.Pdf);
ELSLogHelper.InsertInfoLog(ELSLogHelper.AsposeLogMessage("Save"), MethodBase.GetCurrentMethod()?.Name, MethodBase.GetCurrentMethod().DeclaringType?.Name, Environment.StackTrace);
streamDocx.Close();
docToAdd = new Document(streamPdf);
ELSLogHelper.InsertInfoLog(ELSLogHelper.AsposeLogMessage("Open"), MethodBase.GetCurrentMethod()?.Name, MethodBase.GetCurrentMethod().DeclaringType?.Name, Environment.StackTrace);
if (File.Exists(tempPath))
{
File.Delete(tempPath);
}
return docToAdd;
}
Here is the code we used when converting it to a stream
private Document ConvertBadDocument(Document docToAdd)
{
MemoryStream streamDocx = new MemoryStream();
docToAdd.Save(streamDocx, SaveFormat.DocX);
ELSLogHelper.InsertInfoLog(_callContext, ELSLogHelper.AsposeLogMessage("Save"), MethodBase.GetCurrentMethod()?.Name, MethodBase.GetCurrentMethod().DeclaringType?.Name, Environment.StackTrace);
var docx = new wordsAspose.Document(streamDocx);
ELSLogHelper.InsertInfoLog(_callContext, ELSLogHelper.AsposeLogMessage("Open"), MethodBase.GetCurrentMethod()?.Name, MethodBase.GetCurrentMethod().DeclaringType?.Name, Environment.StackTrace);
MemoryStream streamPdf = new MemoryStream();
docx.Save(streamPdf, wordsAspose.SaveFormat.Pdf);
ELSLogHelper.InsertInfoLog(_callContext, ELSLogHelper.AsposeLogMessage("Save"), MethodBase.GetCurrentMethod()?.Name, MethodBase.GetCurrentMethod().DeclaringType?.Name, Environment.StackTrace);
streamDocx.Close();
docToAdd = new Document(streamPdf);
ELSLogHelper.InsertInfoLog(_callContext, ELSLogHelper.AsposeLogMessage("Open"), MethodBase.GetCurrentMethod()?.Name, MethodBase.GetCurrentMethod().DeclaringType?.Name, Environment.StackTrace);
return docToAdd;
}