Skip to content
This repository has been archived by the owner on Jun 25, 2024. It is now read-only.

Add file name feature to directive params #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions demo/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="en" data-ng-app="app" ng-controller="AppCtrl">
<html lang="en" data-ng-app="app" ng-controller="AppCtrl" dir="ltr">
<head>
<meta charset="utf-8"/>
<title>Angular PDF.js demo</title>
Expand Down Expand Up @@ -31,11 +31,16 @@
<!-- Example of loading pdf from URL string. Note that this must be an interpolation string -->
<pdfjs-viewer src="{{ pdf.src }}"></pdfjs-viewer>

<!--
Example of loading pdf from raw binary data. Note that this must be a scope variable.
Passing file name attribute
-->
<!--<pdfjs-viewer data="pdf.data" file-name="example.pdf"></pdfjs-viewer> -->
<!--
Example of loading pdf from raw binary data. Note that this must be a scope variable.
Comment upper viewer out if you use this viewer (because multi pdf viewers are currently not supported)
-->
<!-- <pdfjs-viewer data="pdf.data"></pdfjs-viewer> -->
<!--<pdfjs-viewer data="pdf.data"></pdfjs-viewer> -->
</div>
</body>
</html>
23 changes: 19 additions & 4 deletions dist/angular-pdfjs-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,14 +373,15 @@
'\n' +
' </div> <!-- outerContainer -->\n' +
' <div id="printContainer"></div>\n' +
' </pdfjs-wrapper>',
' </pdfjs-wrapper>\n',
restrict: 'E',
scope: {
onInit: '&',
onPageLoad: '&',
scale: '=?',
src: '@?',
data: '=?'
data: '=?',
fileName: '@?'
},
link: function ($scope, $element, $attrs) {
$element.children().wrap('<div class="pdfjs" style="width: 100%; height: 100%;"></div>');
Expand Down Expand Up @@ -466,8 +467,16 @@
if (!src && !data) {
return;
}

window.PDFViewerApplication.open(src || data);
if (src) {
window.PDFViewerApplication.open(src);
} else if (data) {
if ($scope.fileName) {
// Passing fileName through url parameter
window.PDFViewerApplication.open(data, {url: $scope.fileName});
} else {
window.PDFViewerApplication.open(data);
}
}
});

// watch other attributes
Expand Down Expand Up @@ -496,8 +505,14 @@
if ($attrs.height) {
document.getElementById('outerContainer').style.height = $attrs.height;
}

if ($attrs.sidebar === 'false') {
document.getElementById('sidebarToggle').setAttribute('hidden', 'true');
}
});
}
};
}]);

//
}();
19 changes: 16 additions & 3 deletions src/angular-pdfjs-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@
onPageLoad: '&',
scale: '=?',
src: '@?',
data: '=?'
data: '=?',
fileName: '@?'
},
link: function ($scope, $element, $attrs) {
$element.children().wrap('<div class="pdfjs" style="width: 100%; height: 100%;"></div>');
Expand Down Expand Up @@ -163,8 +164,16 @@
if (!src && !data) {
return;
}

window.PDFViewerApplication.open(src || data);
if (src) {
window.PDFViewerApplication.open(src);
} else if (data) {
if ($scope.fileName) {
// Passing fileName through url parameter
window.PDFViewerApplication.open(data, {url: $scope.fileName});
} else {
window.PDFViewerApplication.open(data);
}
}
});

// watch other attributes
Expand Down Expand Up @@ -193,6 +202,10 @@
if ($attrs.height) {
document.getElementById('outerContainer').style.height = $attrs.height;
}

if ($attrs.sidebar === 'false') {
document.getElementById('sidebarToggle').setAttribute('hidden', 'true');
}
});
}
};
Expand Down