所以下面的这段代码可以正常工作,可以完成工作-word-> PDF。
只有一个问题,当单词doc的表中包含有单元格时,将单词doc转换为pdf时,pdf会显示单元格合并但内部没有值。
有人知道为什么吗?有什么解决办法吗?
注意:这是在服务器端进行的转换。
if (nomeDocTemplate == attachment)
{
web.AllowUnsafeUpdates = true;
string wordEdit =item2.Attachments.UrlPrefix + "Template" + item.ID + ".docx";
string wordAutomationServiceName = "Word Automation Services";
string filenamedest = web.Url + item.File.ServerRelativeUrl;
SPFile attachmentFile = item2.Web.GetFile(wordEdit);
using (MemoryStream destinationStream = new MemoryStream())
{
//Call the syncConverter class, passing in the name of the Word Automation Service for your Farm.
SyncConverter sc = new SyncConverter(wordAutomationServiceName);
////Pass in your User Token or credentials under which this conversion job is executed.
sc.UserToken = SPContext.Current.Site.UserToken;
sc.Settings.UpdateFields = true;
//Save format
sc.Settings.OutputFormat = SaveFormat.PDF;
////Convert to PDF by opening the file stream, and then converting to the destination memory stream.
ConversionItemInfo info = sc.Convert(attachmentFile.OpenBinaryStream(), destinationStream);
var filename = Path.GetFileNameWithoutExtension(item.File.Name) + ".pdf";
if (info.Succeeded)
{
//File conversion successful, then add the memory stream to the SharePoint list.
SPFile newfile = web.Lists["Tramitar"].RootFolder.Files.Add(filename, destinationStream, true);
}
else if (info.Failed)
{
throw new Exception(info.ErrorMessage);
}
}
//ConcatAndAddContent(anexosProcesso);
return;
}
以下是doc和pdf,以更好地了解我遇到的问题: