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

April 27, 2016
April 25, 2016

As I said in the previous post, we implemented the pdffix.js. However we noticed that the PDF files open in Acrobat Reader even if the user has Acrobat Pro installed. Do you experience the same behavior? Do you know how to change it?

February 2, 2016

Hii everyone, I am new to this forum.. Your answer is really useful for me. Thanks for sharing valuable information.

Regards..

Big Data Training in Chennai | Primavera Training in Chennai | Big Data Training in Chennai

December 27, 2015

Has anyone tested this on a My Sites site collection? This solution is working great on our Portal sites, but it doesn’t seem to work in user’s OneDrive folders on My Sites. Adobe tries to open the PDF, but gives the error “There was an error opening this document. File open failed.” In addition it seems to cause Folder names to disappear randomly within OneDrive document libraries. Any idea why this would act differently on a My Sites site collection?    http://www.traininginsholinganallur.in/web-designing-training-in-chennai.html  |   http://www.traininginsholinganallur.in/php-training-in-chennai.html

MadHockeyGoon
Participant
March 5, 2015

I'm not sure if I'm adding to the confusion or actually answering the issue. I'm running SharePoint Server 2013 Standard SP1 on 2012 R2. I was on this site a couple times because my users like to modify .pdf's after uploaded. After the said CU, which I applied October 2014, check out from SharePoint was broken. .pdf's could be checked out via Acrobat, but, extra steps for my users make them angry. By coincidence, I rebuilt a few SharePoint service applications and magically, checking .pdf's in and out via SharePoint works again. Now, here is where you get mad at me because I don't 100% remember which services I rebuilt. I believe it was BDC, state service, secure store, and word automation. I can tell you I didn't touch search, metadata, or user profile. I haven't tested this in any manner, but I throw this out there in case it's actually a resolution for the problem. Good luck!

kevinmcqn
Participant
January 22, 2015

Has anyone tested this on a My Sites site collection? This solution is working great on our Portal sites, but it doesn't seem to work in user's OneDrive folders on My Sites. Adobe tries to open the PDF, but gives the error "There was an error opening this document. File open failed." In addition it seems to cause Folder names to disappear randomly within OneDrive document libraries. Any idea why this would act differently on a My Sites site collection?

January 6, 2015

If the fix provided above doesn't help, try it in addition to changing IE Options -> Security -> Select appropriate zone -> Custom Level ->

and set Automatic propmpting for ActiveX controls to Enabled.


Regards.

Participant
October 16, 2014

We ran across this issue updating from RTM to SP1 (SP 2013). I was able to implement the PDFFIX.js and have it working on a couple of site collections in our test environment.

I also have an active support ticket open with MS who sent me the link to this forum post and the following day (yesterday) sent me the exact instructions that are posted above. It seems in the time they have been doing "triage" in their product evaluation team, they still have no real fix for the issue. I am continuing to push for an actual fix/patch before implementing this in our production environment.

cs

April 13, 2015

Hi Chris,

I am still facing the error "There was an error opening this document. The filename, directory name, or volume label syntax is incorrect." even after replacing

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

with:

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

Please let me know if you have done any other changes to resolve this issue.

Thanks,

Varun

marier69941498
Participant
May 12, 2015

I have no idea if this helps, as I am not tech savvy. But I did have this exact message today and have resolved it.  Here was my issue and resolution.

I couldn't open a pdf document I had just saved in a folder I created on our company drive ( just like I always do). However, I could view/open that same pdf if I opened it directly from the email I received it in (I use Microsoft Outlook). Also, I could  still view/open other pdf's previously saved throughout my other computer files. Just not the newest pdf that I had saved.

I figured out that where I was trying to save the pdf had a file path that was too long (for whatever reason. - maybe this is exactly what you guys are trying to fix... I don't really know). In other words it was saved in a folder that was 8 folders away (deep) from my computer drive. For some reason that seams to be the cutoff length for my adobe. Anyway, I simply saved the pdf one folder up and it works perfect.

Hope this helps in some way!

Marie

July 24, 2014

I have applied CU's Dec 2013 for SharePoint 2013 Server. PDF file opening in browser. I applied above mentioned PDFFIX.js script. But getting same result.

I need to show "Check Out and Open" PDF files in document libraries in Sharepoint 2013.

Participant
July 7, 2014

I keep getting an error about the linkfile name

You cannot call a method on a null-valued expression.


At line:3 char:1


+ $field = $web.Fields.GetFieldByInternalName("LinkFilename")

Then I get this error

The property 'JSLink' cannot be found on this object. Verify that the property exists and can be set.


At line:4 char:1


+ $field.JSLink = "/_layouts/15/PdfFix.js"

Even though I confrim the file is there? Please help any one?

January 6, 2015

Hi shellsdog,

It is possible that you provided invalid library name. Library name and "name" from url may differ, so you can try to check library name by going to library settings.

Regards.