SharePoint 2020

The Vision for a Future of Clarity

Save list item as PDF file from Display Form using SWF buttons

This article explains how to add swf Flash buttons using TableTools to your List View and Default Display Form.

I’ve tested this in SharePoint 2010, using IE8. I have not tested this in SharePoint 2013 but it would work there too.

This is a pure front-end solution, using only SP Designer or notepad for those on a locked down intranet.

The only requirement is that your browser needs to be able to display Flash and SWF files.

The original post and code came from Danish Islam, which explains the how the code and buttons are linked to a List View.

Use jQuery Datatables for SharePoint List Webpart with export to CSV, EXCEL, PDF and Print features

The buttons contained in jQuery Datatable TableTools are:

Copy, CSV, Excel, PDF, Print.

buttons

This is the result of adding the script to the List View:

listTableTools

Note: The search box is live “Search as you type” filtering the list. The paging is Ajax and loads instantly.

All that you require are:

  • The files to be uploaded
  • Change the file paths in the the code
  • Change the file paths of the images in the CSS files.
  • Add a Content Editor Web Part to your List View or Display Form view.

If you place this script in a content editor web part above a list view, the full affect of Datatable Tabletools will be displayed.

Also, important note: Use the jQuery.js file that comes with the Datatables Zip Package.  Using jQuery v1.12 the buttons did NOT display and it took me a couple hours to determine it was the jQuery.js file.

<style type="text/css">
.even, .odd, .sorting_1 {
 background-color: transparent !important;
}
.dataTable THEAD TH {
 border: 0 !important;
}
</style>
<script type="text/javascript" src="/scripts/datatables/jquery.js"></script>
<script type="text/javascript" src="/scripts/datatables/jquery.dataTables.min.js"></script>
<link type="text/css" rel="stylesheet" href="/scripts/datatables/css/jquery.dataTables.css">
<script type="text/javascript" src="/scripts/datatables/dataTables.tableTools.js"></script>
<link type="text/css" rel="stylesheet" href="/scripts/datatables/css/dataTables.tableTools.css">

<script type="text/javascript" >
 $(document).ready(function(){
 $(".ms-listviewtable").prepend($("<thead></thead>").append($(".ms-listviewtable").find("tr:first"))).DataTable({"sDom": 'T<"clear">lfrtip', 

 "tableTools": {
 "sSwfPath": "/scripts/datatables/copy_csv_xls_pdf.swf"
 // Change this path according to file location 

 } 

 });
 });
</script>

For a List Display Item, I removed the CSV and Excel buttons and also added an “Email Link” button.

displayform


<style type="text/css">
.even, .odd, .sorting_1 {
background-color: transparent !important;
}
.dataTable THEAD TH {
border: 0 !important;
}
</style>
<link type="text/css" rel="stylesheet" href="/scripts/datatables/css/jquery.dataTables.css">
<link type="text/css" rel="stylesheet" href="/scripts/datatables/css/dataTables.tableTools.css">
<script type="text/javascript" src="/scripts/datatables/jquery.js"></script>
<script type="text/javascript" src="/scripts/datatables/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="/scripts/datatables/dataTables.tableTools.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".ms-formtable").prepend($("<thead></thead>").append($(".ms-formtable").find("tr:first"))).DataTable({"sDom": 'T<"clear">rt',
"tableTools": {
"sSwfPath": "/scripts/datatables/copy_csv_xls_pdf.swf",

"aButtons": [

{

"sExtends": "copy",
"sButtonText": "Copy to clipboard"
},
{
"sExtends": "pdf",
"sButtonText": "Save as PDF",

"fnComplete": function ( nButton, oConfig, oFlash, sFlash ) {
SP.UI.Notify.addNotification('<img src="/_layouts/images/loadingcirclests16.gif" style="vertical-align: top;"/> PDF Exported to file ...',false);
}
},
{

"sExtends": "print",
"sButtonText": "Print this item"
},

{

"sExtends":    "text",
"sButtonText": "Email link",
"sButtonClass":  "DTTT_button_csv",
"fnClick": function ( nButton, oConfig, oFlash ) {
window.location='mailto:?subject=' + document.title + '&body=' + window.location;
}
}
]
} // end of tabletools

});

});

</script>

The Saving to PDF button is the only front-end solution I have found that works without for IE8 and SharePoint 2010.

Any comments, questions, hit me up. Enjoy.

 

August 9, 2015 Posted by | SharePoint 2010, SharePoint Designer 2010, SharePoint Javascript | , , , | 7 Comments