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;
}