Skip to main content
Participant
January 14, 2014
Answered

Sharepoint 2013 PDF check out and open option

  • January 14, 2014
  • 12 replies
  • 65264 views

A few months back I made the change to my DOCICON.xml file to enable the integration with Acrobat and Sharepoint to prompt the user to "Check Out and Open" PDF files in document libraries in Sharepoint 2013. It worked fine and as expected.

After applying CU's to Sharepoint up to October 2013, this function seems to have gone away. I verified that the DOCICON.xml settings are correct.  Ex: <Mapping Key="pdf" Value="pdficon_small.png" OpenControl="AdobeAcrobat.OpenDocuments" />

I can still get the "check out..." prompt if I open the document libraries with Windows Explorer, but not when PDF's are opened directly on Sharepoint. I have a support case opened with Microsoft, but they seem to point the problem at Adobe.

I have verified that the AcroPDF.dll is on each client and is enabled in IE. The PDF files open with Acrobat, but the check out prompt is not showing up unless I open the Sharepoint library with Explorer.

Have tried different Acrobat versions (10 and 11) as well as different IE versions (9,10,11)..etc...and Windows 7 or Windows 8, but the check out function does not seem to work when opening PDF's directly from Sharepoint 2013

This topic has been closed for replies.
Correct answer EricHallgren

Microsoft support just helped me with this issue. A published fix is likely to come out soon. The following steps are just my re-write of their instructions. As with all fixes or workarounds, I recommend you test first.

Other things to be aware of before you implement this is that all PDF files will open with the "check-out" function whether or not your library settings say "open in browser" or not and I don't think any other settings will matter as the javascript file is controlling. Changes you make to the docicon.xml won't matter either.

STEPS

You need to create a javascript file, the contents are at the end of this post. Copy the contents between the “***” to notepad or other text editor and save it as “PDFFIX.js”.

Copy the file (pdffix.js) to your Sharepoint server - C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\LAYOUTS

Run the powershell commands on your Sharepoint server below depending on what you want to fix, either a single library or site collection. You may also need to clear IE cache on your client.

Powershell commands assume admin and Sharepoint tools loaded or you are running from the management shell.

SINGLE DOC LIBRARY

$web = Get-SPWeb http://urltoweb
$list = $web.Lists["nameoflist"]
$field = $list.Fields.GetFieldByInternalName("LinkFilename")
$field.JSLink = "/_layouts/15/PdfFix.js"
$field.Update($true)

SITE COLLECTION

$site = Get-SPSite http://”yoursite”-no quotes
$web = $site.RootWeb
$field = $web.Fields.GetFieldByInternalName("LinkFilename")
$field.JSLink = "/_layouts/15/PdfFix.js"
$field.Update($true) #push change down to all lists

To uninstall the fix use this:

$site = Get-SPSite http:// ”yoursite”-no quotes
$web = $site.RootWeb
$field = $web.Fields.GetFieldByInternalName("LinkFilename")
$field.JSLink = ""
$field.Update($true) #push change down to all lists

  

*****CONTENTS OF PDFFIX.js*****

(function () {

    if (typeof SPClientTemplates === 'undefined')

        return;

    var PdfCtx = {};

    PdfCtx.Templates = {};

    PdfCtx.Templates.Fields = { 'LinkFilename': { 'View': PdfClientLinkFilenameNoMenu } };

    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(PdfCtx);

})();

function GetExtension(szHref) {

    var sz = new String(szHref);

    var re = /^.*\.([^\.]*)$/;

    return (sz.replace(re, "$1")).toLowerCase();

}

var stsOpen = null;

function IsPdfClientInstalled() {

    if (stsOpen == null) {

        if (Boolean(window.ActiveXObject)) {

            try {

                stsOpen = new ActiveXObject("PdfFile.OpenDocuments");

            }

            catch (e) {

                stsOpen = null;

            }

        }

    }

    return (stsOpen != null);   

}

function OpenPdfInClient(pdfFileUrl) {   

    var fRet = true;

    try {

        fRet = typeof stsOpen.ViewDocument2 != "undefined" && stsOpen.ViewDocument2(window, pdfFileUrl, '');

    }

    catch (e) {

        fRet = false;

    };

    if (event != null) {

        event.cancelBubble = true;

        event.returnValue = false;

    }

    return fRet;

}

function PdfNewGif(listItem, listSchema, ret) {

    if (listItem["Created_x0020_Date.ifnew"] == "1") {

        var spCommonSrc = GetThemedImageUrl("spcommon.png");

        ret.push("<span class=\"ms-newdocument-iconouter\"><img class=\"ms-newdocument-icon\" src=\"");

        ret.push(spCommonSrc);

        ret.push("\" alt=\"");

        ret.push(Strings.STS.L_SPClientNew);

        ret.push("\" title=\"");

        ret.push(Strings.STS.L_SPClientNew);

        ret.push("\" /></span>");

    }

}

function PdfClientLinkFilenameNoMenu(param1, param2, listItem, listSchema) {

    var ret = [];

    var fileUrl = listItem.FileRef;

    if (fileUrl != null && typeof fileUrl != 'undefined' && TrimSpaces(fileUrl) != "") {

        if (listItem.FSObjType == '1') {

            if (listSchema.IsDocLib == '1') {

                RenderDocFolderLink(ret, listItem.FileLeafRef, listItem, listSchema);

            }

            else {

                RenderListFolderLink(ret, listItem.FileLeafRef, listItem, listSchema);

            }

        }

        else {

            ret.push("<a class='ms-listlink' href=\"");

            ret.push(listItem.FileRef);

            ret.push("\" onmousedown=\"return VerifyHref(this,event,'");

            ret.push(listSchema.DefaultItemOpen);

            ret.push("','");

            ret.push(listItem["HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon"]);

            ret.push("','");

            ret.push(listItem["serverurl.progid"]);

            ret.push("')\" onclick=\"");

            var appInstalled = IsPdfClientInstalled();

            var szExt = GetExtension(listItem.FileRef);

            if (appInstalled && szExt == 'pdf' && browseris.ie) {

                ret.push("return OpenPdfInClient('");

                ret.push("http://");

                ret.push(window.location.hostname);

                ret.push(listItem.FileRef);

            }

            else {

                ret.push("return DispEx(this,event,'TRUE','FALSE','");

                ret.push(listItem["File_x0020_Type.url"]);

                ret.push("','");

                ret.push(listItem["File_x0020_Type.progid"]);

                ret.push("','");

                ret.push(listSchema.DefaultItemOpen);

                ret.push("','");

                ret.push(listItem["HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon"]);

                ret.push("','");

                ret.push(listItem["HTML_x0020_File_x0020_Type"]);

                ret.push("','");

                ret.push(listItem["serverurl.progid"]);

                ret.push("','");

                ret.push(Boolean(listItem["CheckoutUser"]) ? listItem["CheckoutUser"][0].id : '');

                ret.push("','");

                ret.push(listSchema.Userid);

                ret.push("','");

                ret.push(listSchema.ForceCheckout);

                ret.push("','");

                ret.push(listItem.IsCheckedoutToLocal);

                ret.push("','");

                ret.push(listItem.PermMask);

            }

            ret.push("')\">");

            var fileRef = listItem["FileLeafRef"];

            if (fileRef != null) {

                var index = fileRef.lastIndexOf('.');

                fileRef = index >= 0 ? fileRef.substring(0, index) : fileRef;

            }

            ret.push(fileRef);

            ret.push("</a>");

            PdfNewGif(listItem, listSchema, ret);

        }

    }

    else {

        ret.push("<nobr>");

        ret.push(listItem["FileLeafRef"]);

        ret.push("</nobr>");

    }

    return ret.join('');

}

************END CONTENTS OF PDFFIX.js***********************

12 replies

EricHallgrenAuthorCorrect answer
Participant
March 19, 2014

Microsoft support just helped me with this issue. A published fix is likely to come out soon. The following steps are just my re-write of their instructions. As with all fixes or workarounds, I recommend you test first.

Other things to be aware of before you implement this is that all PDF files will open with the "check-out" function whether or not your library settings say "open in browser" or not and I don't think any other settings will matter as the javascript file is controlling. Changes you make to the docicon.xml won't matter either.

STEPS

You need to create a javascript file, the contents are at the end of this post. Copy the contents between the “***” to notepad or other text editor and save it as “PDFFIX.js”.

Copy the file (pdffix.js) to your Sharepoint server - C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\LAYOUTS

Run the powershell commands on your Sharepoint server below depending on what you want to fix, either a single library or site collection. You may also need to clear IE cache on your client.

Powershell commands assume admin and Sharepoint tools loaded or you are running from the management shell.

SINGLE DOC LIBRARY

$web = Get-SPWeb http://urltoweb
$list = $web.Lists["nameoflist"]
$field = $list.Fields.GetFieldByInternalName("LinkFilename")
$field.JSLink = "/_layouts/15/PdfFix.js"
$field.Update($true)

SITE COLLECTION

$site = Get-SPSite http://”yoursite”-no quotes
$web = $site.RootWeb
$field = $web.Fields.GetFieldByInternalName("LinkFilename")
$field.JSLink = "/_layouts/15/PdfFix.js"
$field.Update($true) #push change down to all lists

To uninstall the fix use this:

$site = Get-SPSite http:// ”yoursite”-no quotes
$web = $site.RootWeb
$field = $web.Fields.GetFieldByInternalName("LinkFilename")
$field.JSLink = ""
$field.Update($true) #push change down to all lists

  

*****CONTENTS OF PDFFIX.js*****

(function () {

    if (typeof SPClientTemplates === 'undefined')

        return;

    var PdfCtx = {};

    PdfCtx.Templates = {};

    PdfCtx.Templates.Fields = { 'LinkFilename': { 'View': PdfClientLinkFilenameNoMenu } };

    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(PdfCtx);

})();

function GetExtension(szHref) {

    var sz = new String(szHref);

    var re = /^.*\.([^\.]*)$/;

    return (sz.replace(re, "$1")).toLowerCase();

}

var stsOpen = null;

function IsPdfClientInstalled() {

    if (stsOpen == null) {

        if (Boolean(window.ActiveXObject)) {

            try {

                stsOpen = new ActiveXObject("PdfFile.OpenDocuments");

            }

            catch (e) {

                stsOpen = null;

            }

        }

    }

    return (stsOpen != null);   

}

function OpenPdfInClient(pdfFileUrl) {   

    var fRet = true;

    try {

        fRet = typeof stsOpen.ViewDocument2 != "undefined" && stsOpen.ViewDocument2(window, pdfFileUrl, '');

    }

    catch (e) {

        fRet = false;

    };

    if (event != null) {

        event.cancelBubble = true;

        event.returnValue = false;

    }

    return fRet;

}

function PdfNewGif(listItem, listSchema, ret) {

    if (listItem["Created_x0020_Date.ifnew"] == "1") {

        var spCommonSrc = GetThemedImageUrl("spcommon.png");

        ret.push("<span class=\"ms-newdocument-iconouter\"><img class=\"ms-newdocument-icon\" src=\"");

        ret.push(spCommonSrc);

        ret.push("\" alt=\"");

        ret.push(Strings.STS.L_SPClientNew);

        ret.push("\" title=\"");

        ret.push(Strings.STS.L_SPClientNew);

        ret.push("\" /></span>");

    }

}

function PdfClientLinkFilenameNoMenu(param1, param2, listItem, listSchema) {

    var ret = [];

    var fileUrl = listItem.FileRef;

    if (fileUrl != null && typeof fileUrl != 'undefined' && TrimSpaces(fileUrl) != "") {

        if (listItem.FSObjType == '1') {

            if (listSchema.IsDocLib == '1') {

                RenderDocFolderLink(ret, listItem.FileLeafRef, listItem, listSchema);

            }

            else {

                RenderListFolderLink(ret, listItem.FileLeafRef, listItem, listSchema);

            }

        }

        else {

            ret.push("<a class='ms-listlink' href=\"");

            ret.push(listItem.FileRef);

            ret.push("\" onmousedown=\"return VerifyHref(this,event,'");

            ret.push(listSchema.DefaultItemOpen);

            ret.push("','");

            ret.push(listItem["HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon"]);

            ret.push("','");

            ret.push(listItem["serverurl.progid"]);

            ret.push("')\" onclick=\"");

            var appInstalled = IsPdfClientInstalled();

            var szExt = GetExtension(listItem.FileRef);

            if (appInstalled && szExt == 'pdf' && browseris.ie) {

                ret.push("return OpenPdfInClient('");

                ret.push("http://");

                ret.push(window.location.hostname);

                ret.push(listItem.FileRef);

            }

            else {

                ret.push("return DispEx(this,event,'TRUE','FALSE','");

                ret.push(listItem["File_x0020_Type.url"]);

                ret.push("','");

                ret.push(listItem["File_x0020_Type.progid"]);

                ret.push("','");

                ret.push(listSchema.DefaultItemOpen);

                ret.push("','");

                ret.push(listItem["HTML_x0020_File_x0020_Type.File_x0020_Type.mapcon"]);

                ret.push("','");

                ret.push(listItem["HTML_x0020_File_x0020_Type"]);

                ret.push("','");

                ret.push(listItem["serverurl.progid"]);

                ret.push("','");

                ret.push(Boolean(listItem["CheckoutUser"]) ? listItem["CheckoutUser"][0].id : '');

                ret.push("','");

                ret.push(listSchema.Userid);

                ret.push("','");

                ret.push(listSchema.ForceCheckout);

                ret.push("','");

                ret.push(listItem.IsCheckedoutToLocal);

                ret.push("','");

                ret.push(listItem.PermMask);

            }

            ret.push("')\">");

            var fileRef = listItem["FileLeafRef"];

            if (fileRef != null) {

                var index = fileRef.lastIndexOf('.');

                fileRef = index >= 0 ? fileRef.substring(0, index) : fileRef;

            }

            ret.push(fileRef);

            ret.push("</a>");

            PdfNewGif(listItem, listSchema, ret);

        }

    }

    else {

        ret.push("<nobr>");

        ret.push(listItem["FileLeafRef"]);

        ret.push("</nobr>");

    }

    return ret.join('');

}

************END CONTENTS OF PDFFIX.js***********************

Participant
April 23, 2014

There was nothing else you had to do?

When I try this and try to open a PDF I get

"There was an error opening this document. The filename, directory name, or volume label syntax is incorrect."

We are on 2013 SP1.

(I thought the url would be a clue as on this link (http://social.msdn.microsoft.com/Forums/en-US/545efcc6-b748-4df8-aee0-7f57f778ad1e/sharepoint-2010-opening-pdfs-in-search-results-the-filename-directory-name-or-volume-label?forum=sharepointgeneralprevious) but having put an alert and making some edits to the js above, no matter what url I use it gives me the error)

I also have been trying to figure out what makes the search results different, to try to replicate that.

Chris Buchholz

June 6, 2014

Hi Chris,

I applied this fix on my test environment and it worked fine.

But, when I applied same solution on production, I faced the issue you have.

The problem was that my test is on http and production is on https.

I fixed this issue by replacing

ret.push("http://");

with:

ret.push(window.location.protocol + "//");

in PDFFIX.js file.

I hope it helps.

Regards.

Participant
January 23, 2014

We have the same problem.  We noticed it was no longer working after the March cummulative update for SP 2013.  Have you found a solution yet? 

Participant
January 23, 2014

We have a support case open with Microsoft and about a week ago, Microsoft confirmed a bug in the March 2013 updates. The java script is not executing a call to the active-x control on the client PC. We submitted the paperwork to get a hotfix created, don't know how this works with them, sounds like they have a committee to review requests like this, so I am hopeful we will get a fix soon, but no time frame given.

Another workaround is to search the document library and open the PDF's via the search results (assuming youi have searching enabled), then you should also get the "open" prompt.

Participant
January 23, 2014

Thank you for your response.  Do you mind keeping us posted on any further details as you hear them?