Problem with converting Word to PDF

I have two Words document that I had merged using OpenXml and saved to SharePoint with a unique name (.dotx). I pass the filename to a function (see below ) to convert the file the PDF. However, for some reason, the pdf is not the same as the file; rather, it's the original file prior to merging. I've viewed the file and it opens with the merge contents.I have two Words document that I had merged using OpenXml and saved to SharePoint with a unique name. I pass the filename to a function (see below ) to convert the file the PDF. However, for some reason, the pdf is not the same as the file; rather, it's the original file prior to merging. I've viewed the file and it opens with the merge contents.

APDocMem.Position = 0;

byte[] content = APDocMem.ToArray();

SPFile template = SPContext.Current.Web.Files.Add(tmpAPFile, content, true);

template.Update();

APDocMem.Position = 0;

byte[] content = APDocMem.ToArray();

SPFile template = SPContext.Current.Web.Files.Add(tmpAPFile, content, true);

template.Update();

private static bool CreateAPPDF(string FileURL, string APDocName, string PDFDocName)

{

bool isSuccess = true;

//get the temp APDoc to convert to PDF

//SetAsposePDFLicense();

SetAsposeWordLicense();

string tmpAPDocURL = FileURL + "/" + APDocName;

string tmpAPPDFURL = fileUrl + "/" + Path.GetFileNameWithoutExtension(PDFDocName) + ".pdf"; ;

MemoryStream wrdStream = new MemoryStream();

MemoryStream pdfStream = new MemoryStream();

try

{

SPFile tmpAPDoc = SPContext.Current.Web.GetFile(tmpAPDocURL);

if (tmpAPDoc.Exists)

{

Aspose.Words.

Document wrdAPDoc = new Aspose.Words.Document(tmpAPDoc.OpenBinaryStream());

wrdAPDoc.UpdateFields();

wrdAPDoc.UpdateListLabels();

wrdAPDoc.Save(pdfStream, Aspose.Words.

SaveFormat.Pdf);

SPFile tmpPDFFile = SPContext.Current.Web.Files.Add(tmpAPPDFURL, pdfStream, true, "System Generated PDF",false);

tmpPDFFile.Update();

}

}

catch (Exception ex)

{

WriteToULSLog(ex.StackTrace,

"CreateAPPDF", TraceSeverity.High, EventSeverity.ErrorCritical);

isSuccess =

false;

}

return isSuccess;

}

private static bool CreateAPPDF(string FileURL, string APDocName, string PDFDocName)

{

bool isSuccess = true;

//get the temp APDoc to convert to PDF

//SetAsposePDFLicense();

SetAsposeWordLicense();

string tmpAPDocURL = FileURL + "/" + APDocName;

string tmpAPPDFURL = fileUrl + "/" + Path.GetFileNameWithoutExtension(PDFDocName) + ".pdf"; ;

MemoryStream wrdStream = new MemoryStream();

MemoryStream pdfStream = new MemoryStream();

try

{

SPFile tmpAPDoc = SPContext.Current.Web.GetFile(tmpAPDocURL);

if (tmpAPDoc.Exists)

{

Aspose.Words.

Document wrdAPDoc = new Aspose.Words.Document(tmpAPDoc.OpenBinaryStream());

wrdAPDoc.UpdateFields();

wrdAPDoc.UpdateListLabels();

wrdAPDoc.Save(pdfStream, Aspose.Words.

SaveFormat.Pdf);

SPFile tmpPDFFile = SPContext.Current.Web.Files.Add(tmpAPPDFURL, pdfStream, true, "System Generated PDF",false);

tmpPDFFile.Update();

}

}

catch (Exception ex)

{

WriteToULSLog(ex.StackTrace,

"CreateAPPDF", TraceSeverity.High, EventSeverity.ErrorCritical);

isSuccess =

false;

}

return isSuccess;

}

It seems that this is a problem with Aspose.Words version 9.7.0. Once I tried it with the latest version, it works.

Hi there,

Thanks for your inquiry. It is nice to hear from you that your problem has been solved using latest version of Aspose.Words. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.