programming4us
programming4us
WEBSITE

Sharepoint 2013 : Developing Applications Using Office Services - Word Automation Services and the New PowerPoint Automation Services

- How To Install Windows Server 2012 On VirtualBox
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire
7/2/2014 9:30:01 PM

The all-new PowerPoint Automation Services has brought to SharePoint 2013 for PowerPoint presentations, on-premises, what Word Automation Services brought to Word documents for SharePoint in 2010: the ability to convert documents, at server scale, into other formats.


NOTE PowerPoint Automation Services runs on-premises only and not in Office 365 SharePoint Online. This was the case for Word Automation Services for SharePoint 2010 and remains the same for SharePoint 2013.

For Word Automation Services, everything for SharePoint 2010 remains in play for SharePoint 2013. However, the biggest addition is that the architecture for Word Automation Services was reworked to allow for synchronous and asynchronous, on-demand, streamed file conversion to augment the traditional timer job conversions. SharePoint 2010 and 2013 enable you to create a document conversion job that runs on the timed interval of Word Automation Service, which works well to support batch processing of documents. SharePoint administrators can set the time interval for running Word Automation Services to be as often as every one minute, but sometimes that isn’t soon enough. With the redesigned architecture, conversion requests can be submitted and processed in real-time. On demand, streamed requests can be made for one file at a time, and whether synchronously or asynchronously requested, the queue manager/scheduler in the new architecture processes the on-demand request as its highest priority.

PowerPoint Automation Services is the newcomer, so you’ll take a look at it a little more deeply. Organizations often have thousands of PowerPoint presentations that are in various file formats ranging from the PowerPoint 97–2003 binary formats known as .ppt to the newer file formats based on Open XML known as .pptx. Additionally, sometimes you do not want to provide a presentation in its native format to others so you need to convert it to a fixed format such as .pdf or images such as .jpg or .png. This often is the case for presentations that are used at conferences where you want attendees to receive a .pdf version. For business cases like these PowerPoint Automation Services can now provide the server-side performance and scale to move these file conversions out of being an antiquated, laborious, manual process.

Unlike Word Automation Services though, no timer job option exists for PowerPoint Automation Services. Files are streamed, which you can do in a synchronous or asynchronous pattern. Also, the solutions you build for PowerPoint Automation Services will be farm-level solutions; the APIs are only available on the SharePoint server.

You can develop your solution using the Microsoft.Office.Server.PowerPoint.Conversion namespace. Using the namespace you have the classes you need for the types of conversions available. Using the PresentationRequest class you can input the binary .ppt file and output a new .pptx file. For fixed format file conversion, the PdfRequest and XpsRequest classes are used to input either a .ppt or .pptx file and output a .pdf or .xps file, respectively. The PictureRequest class can also take as input a .ppt or .pptx file and output either a .jpg or .png depending on your preference. For exposure to the coding involved, the following Try It Out shows you how to build a small console application to exercise PowerPoint Automation Services.


TRY IT OUT: Converting PowerPoint Presentation Files to .pdf Files Using the New PowerPoint Automation Services (C14PPTAutomationSvcs.zip)

In this exercise you use a simple console application to see the fundamental code pattern to convert .ppt and .pptx files to .pdf using PowerPoint Automation Services. For this Try It Out you need access to a SharePoint 2013 on-premises server development environment with Visual Studio 2012 installed and PowerPoint
Automation Services running on the SharePoint server.

1. Either confirm with your SharePoint Administrator that PowerPoint Automation Services is running in your on-premises environment, or open the SharePoint Administration Console, click Application Management, click Manage Service Applications, and confirm that the PowerPoint Conversion Service Application and Proxy are started. If not, return to Application Management, click Manage Services on Server, locate the PowerPoint Conversion Service, and click the Start link.

2. Run Visual Studio 2012 as Administrator. Select New Project.

3. In the New Project dialog, expand the Templates ⇒ Visual C# ⇒ Windows nodes. Select Console Application and provide the name C14PPTAutomationSvcs. Click OK.

4. When the project loads, close the Program.cs file.

5. In the Solution Explorer, right-click the project and select Properties. On the Application tab confirm the Target framework is set to .NET Framework 4. If it’s not, set it and confirm any prompts and reopen the Properties pane. Click the Build tab, set the Configuration drop-down list to All Configurations, and close the Properties pane.

6. In the Solution Explorer, right-click the project and select Add Reference.

7. In the Reference Manager, under Framework, add System.Web, and under Extensions add Microsoft.SharePoint. Click Browse and navigate to the following location: C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.Office.Server.PowerPoint\v4.0_15.0.0.0__71e9bce111e9429c. Click the Microsoft.Office.Server.PowerPoint.dll, click Add and then click OK.

8. In the Solution Explorer, double-click the Program.cs file to open it. Add the following using statements:
using System.IO; 
using System.Web;
using Microsoft.SharePoint;
using Microsoft.Office.Server.PowerPoint.Conversion;
9. In the Main method, add the following:
            try
{
string mySiteURL = "http://YourServerNameHere/YourSiteHere";
using (SPSite mySite = new SPSite(mySiteURL))
{
using (SPWeb myWeb = mySite.OpenWeb())
{
Console.WriteLine("Convert to .pdf Start");
// Identify document library and input file
SPFolder myDocs = myWeb.Folders[mySiteURL +
"/YourDocumentLibrary"];
SPFile myFile = myDocs.Files[mySiteURL +
"/YourDocumentLibrary/YourPresentationName.pptx"];
// Create a stream object for the file
Stream myFileStream = myFile.OpenBinaryStream();
SPFileStream myStream = new SPFileStream(myWeb, 0x1000);

// Rrequest conversion to .pdf format.
PdfRequest myRequest = new PdfRequest(
myFileStream,
".pptx",
myStream);

// Rrequest is sent synchronously, when
// 'null' value is used for the callback parameter.
// Response is in the result object.
IAsyncResult result = myRequest.BeginConvert(
SPServiceContext.GetContext(mySite),
null,
null);

// Use the EndConvert method to get the result.
myRequest.EndConvert(result);

// Add the converted file to the document library.
SPFile myNewPdfFile = myDocs.Files.Add(
"newConvertedPresentation.pdf",
myStream,
true);
Console.WriteLine("New file name: {0}", myNewPdfFile.Url);
}
}
}
catch (Exception ex)
{
Console.WriteLine("Error Message: " + ex.Message);
}
finally
{
Console.WriteLine("Conversion to .pdf completed.
Press <Enter> to quit.");
Console.ReadLine();
}
10. Open a browser, navigate to a site, and upload any .pptx presentation to test conversion from .pptx to .pdf.

11. After the file is uploaded:
  • Replace the YourServerNameHere/YourSiteHere literal in the mySiteURL variable with the URL for your SharePoint site that includes the full path to your document library.
  • Replace the YourDocumentLibrary literal in the myDocs variable in the code with the name of your document library.
  • Replace the YourDocumentLibrary/YourPresentationName literal in the myFile variable with the code to the document library and name of your presentation file.
  • Optionally, you can replace the newConvertedPresentation literal in the myNewPdfFile value with the name of your presentation.
12. Press F5 to run the code. Depending on the hardware speed of your test server, this might take a minute or two so be patient. The command window will show the name of the file converted when the operation is completed.

13. When the operation completes, close the command window and look in the document library to review the new file.

How It Works

This Try It Out showed the code pattern for using the PdfRequest class for converting a presentation in the .pptx file format to a .pdf format in a synchronous call to PowerPoint Automation Services. Similarly, you can use the PresentationRequest, XpsRequest, and the PictureRequest classes to perform the type of presentation file conversion task unique to each. All the classes inherit from the Request class. Three parameters are required to be passed in: an input stream object for the file to be converted, the dot file extension (.ppt, .pptx, and so on) of the file to be converted, and an output SPFileStream object that designates the dot extension for the output file where it will be saved on SharePoint. The output file must designate the target dot extension that is consistent with the conversion class you are using. For instance, if you use the XpsRequest class, your output dot file extension must be .xps. The exception to this is the PictureRequest class. This class requires an additional parameter to designate the format for the picture to be converted to. You use the PictureFormat enumeration for this and can choose between Default, Png, and Jpg. Also, when designating the output stream dot file extension, you must use .zip.

PowerPoint Automation Services makes a nice addition to the Office server-side services. In this Try It Out you used a console application to make your conversion request, but in a production enterprise environment, you can drive your conversion requests to PowerPoint Automation Services off a variety of SharePoint interactions, whether it’s an end user clicking a button on a web part, an event firing on a list item, or a workflow action calling out to a service endpoint that has access to the SharePoint server. Solutions can also include the use of other technologies such as the Open XML SDK, where you can dynamically augment or generate entire presentations by incorporating data from external data sources, charts or tables from Excel, content from Word, or other PowerPoint presentations for that matter. As with Word Automation Services, PowerPoint Automation Services now joins the ranks for shifting the often manual workload for presentation conversion to other formats into an automated conversion processes on the SharePoint server.

Other  
  •  Sharepoint 2013 : Developing Applications Using Office Services - What’s New in Excel Services
  •  Sharepoint 2013 : Developing Applications Using Office Services - WOPI and the New Office Web Apps Server
  •  Sharepoint 2013 : Building a BCS-enabled Business Solution : Building an Integrated BCS Solution with an App for SharePoint Containing an App for Office
  •  Business Connectivity Services in Apps for SharePoint 2013 : Building an App-level BCS Solution for Office 365 SharePoint Online
  •  Business Connectivity Services in SharePoint 2013 : Adding a Business Data Connectivity Model to Office 365 SharePoint Online
  •  Remote Event Receivers in Sharepoint 2013 : Introducing Remote Event Receivers
  •  InfoPath with SharePoint 2010 : Apply Rich Text to the Entry
  •  InfoPath with SharePoint 2010 : Add Changed Event Code for Tracking Changes
  •  InfoPath with SharePoint 2010 : Set Up the Form for Tracking Changes
  •  Sharepoint 2013 : Farm Management - Rename a Server on the Farm, Display the Configured Managed Paths
  •  
    Top 10
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
    - Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
    - Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
    - Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
    - Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
    - Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
    - Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
    REVIEW
    - First look: Apple Watch

    - 3 Tips for Maintaining Your Cell Phone Battery (part 1)

    - 3 Tips for Maintaining Your Cell Phone Battery (part 2)
    programming4us programming4us
    programming4us
     
     
    programming4us