How to use the Microsoft Word Conversion Service to generate a PDF

Document created by Matthias_Walter Employee on Oct 25, 2018
Version 1Show Document
  • View in full screen mode

If you want to generate a PDF document without an extension you can use the Word conversion service from Office WebApps.

You might know the SharePoint document library possibility of MS Word documents to print as PDF as shown in the figure below.

Lets use skybow Actions to create a document and download it as PDF directly!

Read here how to do that step-by-step.

 

  1. Configure a skybow action links or a button with actions within skybow rich forms e.g. on the displayform
  2. Add two Actions
    1. Type "Generate Document" and save it to a library (in this case it is stored in the folder of the current dossier) skybow Solution Studio - What's a dossier?
      You can as well just save it in any other document library temporarily or not.
    2. Type "Execute Script"

      After the document is being generated simply get it's URL (line 2) and pass it to the Word Viewer of the Office WebApps using type 'downloadpdf'
var webUrl = [[@Web.Url]];
var sourcedoc = [[@Web.QueryList([[@Web.ServerRelativeUrl]]+'/ContractDocuments', '<Where><Eq><FieldRef Name=Editor LookupId=True /><Value Type=User ><UserID/></Value></Eq></Where><OrderBy><FieldRef Name=Created Ascending=False /></OrderBy>', 1, 'UniqueId,FileLeafRef', 'Scope="Recursive"')]];

var sourcedocid = sourcedoc[0]["UniqueId"];
var filename = sourcedoc[0]["FileLeafRef"];

jQuery.get([[@Web.Url]] + "/_layouts/15/WopiFrame.aspx?sourcedoc={" + sourcedocid + "}&file=" + encodeURIComponent(filename) + "&action=default",
  function (data) {
    // Use Microsoft Word Conversion Service to generate a PDF
    var accessToken = jQuery(data).find("input[name='access_token']").val();
    var accessToken_ttl = jQuery(data).find("input[name='access_token_ttl']").val();
    window.location = "https://euc-word-view.officeapps.live.com/wv/WordViewer/request.pdf?WOPIsrc=" + webUrl + "/_vti_bin/wopi.ashx/files/" + sourcedocid + "&access_token=" + accessToken + "&access_token_ttl=" + accessToken_ttl + "&type=downloadpdf";
  }
);

 

Instead of using the skybow document generation you can of course use any other existing word file by passing it's url to the scripts 'sourcedoc' variable (line 2).

 

I hope this helps.

Attachments

    Outcomes