每当文件更新时,我都会尝试将文档库(转换)中的.docx
文件转换为PDF格式。
我正在使用的代码如下:
public override void ItemUpdated(SPItemEventProperties properties)
{
ConversionJob job = new ConversionJob(wordAutomationServiceName);
job.UserToken = properties.Web.CurrentUser.UserToken;
job.Settings.UpdateFields = true;
job.Settings.OutputFormat = SaveFormat.PDF;
string input = siteURL + "Conversion/Test.docx";
string output = siteURL + "Conversion/Test.pdf";
job.AddFile(input, output);
job.Start();
}
当我在调试模式下运行时,它会在没有任何错误或异常的情况下执行,但它不会生成任何PDF文件。
我无法找出问题所在
尝试了这个简单的代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.Office.Word.Server.Conversions;
class Program
{
static void Main(string[] args)
{
string siteUrl = "http://siteurl";
string wordAutomationServiceName = "Word Automation Services";
using (SPSite spSite = new SPSite(siteUrl))
{
ConversionJob job = new ConversionJob(wordAutomationServiceName);
job.UserToken = spSite.UserToken;
job.Settings.UpdateFields = true;
job.Settings.OutputFormat = SaveFormat.PDF;
job.AddFile(siteUrl + "/Shared%20Documents/Test.docx",
siteUrl + "/Shared%20Documents/Test.pdf");
job.Start();
}
}
}
这也没有奏效 我觉得代码中没有错误必须是sharepoint设置的一些问题
答案 0 :(得分:0)
你有一个Document对象吗?
我不确定你是否可以在你的上下文中使用它,但如果是,你可以尝试:
docObject.ExportAsFixedFormat("Yourdoc.pdf", WdExportFormat.wdExportFormatPDF, false,
WdExportOptimizeFor.wdExportOptimizeForPrint, WdExportRange.wdExportAllDocument, 0, 0,
WdExportItem.wdExportDocumentContent, true, true,
WdExportCreateBookmarks.wdExportCreateNoBookmarks, true, false, false, ref oMissing);
更多信息here
答案 1 :(得分:-1)