Added configurable header and footer logos for PDF.

This commit is contained in:
Sean Engelhardt 2017-04-19 14:56:15 +02:00 committed by Emanuel Schütze
parent 06adfa0301
commit 2b94dc5942
4 changed files with 76 additions and 17 deletions

View File

@ -223,7 +223,9 @@ def get_config_variables():
name='logos_available',
default_value=[
'logo_projector_main',
'logo_projector_header'],
'logo_projector_header',
'logo_pdf_header',
'logo_pdf_footer'],
weight=300,
group='Logo',
hidden=True)
@ -247,3 +249,24 @@ def get_config_variables():
weight=302,
group='Logo',
hidden=True)
#PDF logos
yield ConfigVariable(
name='logo_pdf_header',
default_value={
'display_name': 'Header PDF logo',
'path': ''},
input_type='logo',
weight=310,
group='Logo',
hidden=True)
yield ConfigVariable(
name='logo_pdf_footer',
default_value={
'display_name': 'Footer PDF logo',
'path': ''},
input_type='logo',
weight=311,
group='Logo',
hidden=True)

View File

@ -144,18 +144,19 @@ angular.module('OpenSlidesApp.core.pdf', [])
* @param {object} contentProvider - Object with on method `getContent`, which
* returns an array for content
*/
var createInstance = function(contentProvider) {
//images shall contain the the logos as URL: base64Str, just like the converter
var createInstance = function(contentProvider, images) {
// PDF header
var getHeader = function() {
var columns = [];
var logoUrl = Config.get('logo_pdf_header').value.path;
// add here your custom logo (which has to be added to a custom vfs_fonts.js)
// see https://github.com/pdfmake/pdfmake/wiki/Custom-Fonts---client-side
/*
columns.push({
image: 'logo.png',
fit: [180,40]
});*/
if (logoUrl) {
columns.push({
image: images[logoUrl],
fit: [180,40]
});
}
var line1 = [
Config.translate(Config.get('general_event_name').value),
@ -768,7 +769,7 @@ angular.module('OpenSlidesApp.core.pdf', [])
height *= scaleByHeight;
}
alreadyConverted.push({
image: BaseMap[element.getAttribute("src")],
image: images[element.getAttribute("src")],
width: width,
height: height
});
@ -837,7 +838,6 @@ angular.module('OpenSlidesApp.core.pdf', [])
ParseHtml(content, html);
return content;
},
BaseMap = images,
/**
* Creates containerelements for pdfMake
* e.g create("text":"MyText") result in { text: "MyText" }

View File

@ -321,6 +321,7 @@
ng-mouseleave="mediafile.logoHover=false"
ng-show="mediafile.canBeUsedAsLogo()">
<span uib-dropdown>
<<<<<<< e1a95588e7f81cf06db3e753be82bc17a125d059
<span id="dropdownLogo{{ mediafile.id }}" class="pointer nobr" uib-dropdown-toggle>
<span uib-tooltip="{{ 'Manage logos' | translate }}" tooltip-class="nobr">
<span ng-if="!mediafile.isUsedAsLogo()" ng-show="mediafile.hover">
@ -335,6 +336,22 @@
{{ logo.display_name | translate }}<span ng-if="!$last">,</br></span>
</small>
</span>
=======
<span id="dropdownLogo{{ mediafile.id }}" class="pointer nobr"
uib-dropdown-toggle uib-tooltip="{{ 'Manage logos' | translate }}"
tooltip-class="nobr">
<span ng-if="!mediafile.isUsedAsLogo()" ng-show="mediafile.hover">
<i class="fa fa-picture-o"></i>
<i class="fa fa-plus"></i>
</span>
<span ng-if="mediafile.isUsedAsLogo()">
<i class="fa fa-picture-o spacer-right"></i>
<span ng-repeat="logo in mediafile.getLogos()">
<small>
{{ logo.display_name }}
</small>
<span ng-if="!$last"><br /><i class="fa fa-picture-o spacer-right"></i></span>
>>>>>>> add logos in PDF (WIP)
</span>
</span>
<span ng-if="hasProjectorHeaderLogo(mediafile) && mediafile.logoHover"

View File

@ -495,9 +495,11 @@ angular.module('OpenSlidesApp.users.site', [
'osTableSort',
'gettext',
'PdfCreate',
'PDFLayout',
'$q',
function($scope, $state, $http, ngDialog, UserForm, User, Group, PasswordGenerator, Projector, ProjectionDefault,
UserListContentProvider, Config, UserAccessDataListContentProvider, PdfMakeDocumentProvider, gettextCatalog,
UserCsvExport, osTableFilter, osTableSort, gettext, PdfCreate) {
UserCsvExport, osTableFilter, osTableSort, gettext, PdfCreate, PDFLayout, $q) {
User.bindAll({}, $scope, 'users');
Group.bindAll({where: {id: {'>': 1}}}, $scope, 'groups');
$scope.$watch(function () {
@ -685,10 +687,27 @@ angular.module('OpenSlidesApp.users.site', [
// Export as PDF
$scope.pdfExportUserList = function () {
var filename = gettextCatalog.getString("List of participants")+".pdf";
var userListContentProvider = UserListContentProvider.createInstance($scope.usersFiltered, $scope.groups);
var documentProvider = PdfMakeDocumentProvider.createInstance(userListContentProvider);
PdfCreate.download(documentProvider.getDocument(), filename);
var imageMap = {};
var imagePromises = [];
var imageSources = [];
imageSources.push(Config.get('logo_pdf_header').value.path);
imageSources.push(Config.get('logo_pdf_footer').value.path);
imagePromises = _.map(imageSources, function (image_source) {
return PDFLayout.imageURLtoBase64(image_source).then(function (base64Str) {
imageMap[image_source] = base64Str;
});
});
return $q(function (resolve) {
$q.all(imagePromises).then(function(base64Str) {
var filename = gettextCatalog.getString("List of participants")+".pdf";
var userListContentProvider = UserListContentProvider.createInstance($scope.usersFiltered, $scope.groups);
var documentProvider = PdfMakeDocumentProvider.createInstance(userListContentProvider, imageMap);
PdfCreate.download(documentProvider.getDocument(), filename);
});
});
};
$scope.pdfExportUserAccessDataList = function () {
var filename = gettextCatalog.getString("List of access data")+".pdf";
@ -1506,7 +1525,7 @@ angular.module('OpenSlidesApp.users.site', [
},
function (error) {
// Error: Username or password is not correct.
$state.transitionTo($state.current, {msg: error.data.detail}, {
$state.transitionTo($state.current, {msg: error.data.detail}, {
reload: true, inherit: false, notify: true
});
}