前言:
SharePoint PowerPoint Conversion Service 可以将PPT转换为PDF文件,这也是SP自带的功能。本文将要介绍如何使用这一功能。
实践:
1. 创建PowerPoint Conversion Service Application:
$pool =New-SPServiceApplicationPool -Name "SharePoint Web" -Account "contoso\spappadmin"
$ppt = New-SPPowerPointConversionServiceApplication "PowerPoint Conversion Service" -ApplicationPool $pool
New-SPPowerPointConversionServiceApplicationProxy "PowerPoint Conversion Service Proxy" -ServiceApplication $ppt -AddToDefaultGroup
Start-SPServiceInstance | where {$_.TypeName -eq "PowerPoint Conversion Service"}
2. 引用Microsoft.Office.Server.PowerPoint.Conversion程序集,位置:C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.Office.Server.PowerPoint\v4.0_16.0.0.0__71e9bce111e9429c
3.调用PresentationRequest class编写代码:
try
{
string siteURL = "http://sp2016";
using (SPSite site = new SPSite(siteURL))
{
using (SPWeb web = site.OpenWeb())
{
Console.WriteLine("Begin conversion");
// Get a reference to the "Shared Documents" library
// and the presentation file to be converted.
SPFolder docs = web.Folders[siteURL +
"/PushDoc"];
SPFile file = docs.Files[siteURL +
"/PushDoc/test.pptx"];
// Convert the file to a stream and create an
// SPFileStream object for the conversion output.
Stream fStream = file.OpenBinaryStream();
SPFileStream stream = new SPFileStream(web, 0x1000);
// Create the presentation conversion request.
PresentationRequest request = new PresentationRequest(
fStream,
".pptx",
stream);
// Send the request synchronously, passing
// in a 'null' value for the callback parameter,
// and capturing the response in the result object.
IAsyncResult result = request.BeginConvert(
SPServiceContext.GetContext(site),
null,
null);
// Use the EndConvert method to get the result.
request.EndConvert(result);
// Add the converted file to the document library.
SPFile newFile = docs.Files.Add(
"newPres1.pptx",
stream,
true);
Console.WriteLine("Output: {0}", newFile.Url);
}
}
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
finally
{
Console.WriteLine("Complete");
Console.ReadKey();
}
}
总结:
SharePoint PowerPoint Conversion Service 能够将ppt ,pptx,图片等文件转换成pdf文档, 具体的需要自己去操作一下。