SharePoint PowerPoint Conversion Service

前言:

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文档, 具体的需要自己去操作一下。


  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值