diff --git a/src/pretix/control/templates/pretixcontrol/pdf/index.html b/src/pretix/control/templates/pretixcontrol/pdf/index.html
index 030c902bc6..aa2a8ab245 100644
--- a/src/pretix/control/templates/pretixcontrol/pdf/index.html
+++ b/src/pretix/control/templates/pretixcontrol/pdf/index.html
@@ -175,22 +175,33 @@
diff --git a/src/pretix/control/views/pdf.py b/src/pretix/control/views/pdf.py
index a74111acc9..866924147a 100644
--- a/src/pretix/control/views/pdf.py
+++ b/src/pretix/control/views/pdf.py
@@ -2,8 +2,10 @@ import json
import logging
import mimetypes
from datetime import timedelta
+from io import BytesIO
from django.core.files import File
+from django.core.files.base import ContentFile
from django.core.files.storage import default_storage
from django.http import (
FileResponse, HttpResponse, HttpResponseBadRequest, JsonResponse,
@@ -14,6 +16,8 @@ from django.utils.crypto import get_random_string
from django.utils.timezone import now
from django.utils.translation import ugettext as _
from django.views.generic import TemplateView
+from PyPDF2 import PdfFileWriter
+from reportlab.lib.units import mm
from pretix.base.i18n import language
from pretix.base.models import CachedFile, InvoiceAddress, OrderPosition
@@ -117,6 +121,33 @@ class BaseEditorView(EventPermissionRequiredMixin, TemplateView):
self.request.event.settings.set(self.get_background_settings_key(), 'file://' + newname)
def post(self, request, *args, **kwargs):
+ if "emptybackground" in request.POST:
+ p = PdfFileWriter()
+ p.addBlankPage(
+ width=float(request.POST.get('width')) * mm,
+ height=float(request.POST.get('height')) * mm,
+ )
+ buffer = BytesIO()
+ p.write(buffer)
+ buffer.seek(0)
+ c = CachedFile()
+ c.expires = now() + timedelta(days=7)
+ c.date = now()
+ c.filename = 'background_preview.pdf'
+ c.type = 'application/pdf'
+ c.save()
+ c.file.save('empty.pdf', ContentFile(buffer.read()))
+ c.refresh_from_db()
+ return JsonResponse({
+ "status": "ok",
+ "id": c.id,
+ "url": reverse('control:pdf.background', kwargs={
+ 'event': request.event.slug,
+ 'organizer': request.organizer.slug,
+ 'filename': str(c.id)
+ })
+ })
+
if "background" in request.FILES:
error, fileobj = self.process_upload()
if error:
diff --git a/src/pretix/static/pretixcontrol/js/ui/editor.js b/src/pretix/static/pretixcontrol/js/ui/editor.js
index 2511ed1317..0bb4188d8d 100644
--- a/src/pretix/static/pretixcontrol/js/ui/editor.js
+++ b/src/pretix/static/pretixcontrol/js/ui/editor.js
@@ -717,6 +717,30 @@ var editor = {
$("#source-container").hide();
},
+ _create_empty_background: function () {
+ $("#loading-container, #loading-upload").show();
+ $("#loading-upload .progress").show();
+ $('#loading-upload .progress-bar').css('width', 0);
+ $("#fileupload").prop('disabled', true);
+ $(".background-button").addClass("disabled");
+ $.post(window.location.href, {
+ 'csrfmiddlewaretoken': $("input[name=csrfmiddlewaretoken]").val(),
+ 'emptybackground': 'true',
+ 'width': $("#pdf-info-width").val(),
+ 'height': $("#pdf-info-height").val(),
+ }, function (data) {
+ if (data.status === "ok") {
+ editor.uploaded_file_id = data.id;
+ editor._replace_pdf_file(data.url);
+ } else {
+ alert(data.result.error || gettext("Error while uploading your PDF file, please try again."));
+ $("#loading-container, #loading-upload").hide();
+ }
+ $("#fileupload").prop('disabled', false);
+ $(".background-button").removeClass("disabled");
+ }, 'json');
+ },
+
init: function () {
editor.$pdfcv = $("#pdf-canvas");
editor.pdf_url = editor.$pdfcv.attr("data-pdf-url");
@@ -738,6 +762,7 @@ var editor = {
$("#source-container").hide();
+ $("#pdf-empty").on("click", editor._create_empty_background);
$('#fileupload').fileupload({
url: location.href,
dataType: 'json',
@@ -750,7 +775,7 @@ var editor = {
$("#loading-container, #loading-upload").hide();
}
$("#fileupload").prop('disabled', false);
- $(".fileinput-button").removeClass("disabled");
+ $(".background-button").removeClass("disabled");
},
add: function (e, data) {
data.formData = {
@@ -760,7 +785,7 @@ var editor = {
$("#loading-upload .progress").show();
$('#loading-upload .progress-bar').css('width', 0);
$("#fileupload").prop('disabled', true);
- $(".fileinput-button").addClass("disabled");
+ $(".background-button").addClass("disabled");
data.process().done(function () {
data.submit();
});
diff --git a/src/pretix/static/pretixcontrol/scss/_forms.scss b/src/pretix/static/pretixcontrol/scss/_forms.scss
index 89d921d5d3..fb9bccf7e1 100644
--- a/src/pretix/static/pretixcontrol/scss/_forms.scss
+++ b/src/pretix/static/pretixcontrol/scss/_forms.scss
@@ -466,3 +466,6 @@ table td > .checkbox input[type="checkbox"] {
}
}
+.help-inline {
+ color: lighten($text-color, 25%); // lighten the text some for contrast
+}
diff --git a/src/pretix/static/pretixcontrol/scss/pdfeditor.css b/src/pretix/static/pretixcontrol/scss/pdfeditor.css
index 0d499a2e1f..3f71368615 100644
--- a/src/pretix/static/pretixcontrol/scss/pdfeditor.css
+++ b/src/pretix/static/pretixcontrol/scss/pdfeditor.css
@@ -61,3 +61,7 @@ body {
width: 100%;
height: 250px;
}
+.pdf-info .help-inline p {
+ margin-top: 10px;
+ margin-bottom: 0;
+}