Added document and page aspect ration detection, added page size support, print out image dynamic sizing based on page vs. document aspect ratio

This commit is contained in:
Roberto Rosario
2011-05-05 02:31:10 -04:00
parent 9c17a627ec
commit 649871b994
4 changed files with 74 additions and 21 deletions

View File

@@ -0,0 +1,24 @@
PICTURE_ERROR_SMALL = u'picture_error.png'
PICTURE_ERROR_MEDIUM = u'1297211435_error.png'
PICTURE_UNKNOWN_SMALL = u'1299549572_unknown2.png'
PICTURE_UNKNOWN_MEDIUM = u'1299549805_unknown.png'
PAGE_SIZE_A5 = u'a5'
PAGE_SIZE_A4 = u'a4'
PAGE_SIZE_A3 = u'a3'
PAGE_SIZE_B5 = u'b5'
PAGE_SIZE_B4 = u'b4'
PAGE_SIZE_LETTER = u'letter'
PAGE_SIZE_LEGAL = u'legal'
PAGE_SIZE_LEDGER = u'ledger'
PAGE_SIZE_DIMENSIONS = (
(PAGE_SIZE_A5, (u'148mm', u'210mm')),
(PAGE_SIZE_A4, (u'210mm', u'297mm')),
(PAGE_SIZE_A3, (u'297mm', u'420mm')),
(PAGE_SIZE_B5, (u'176mm', u'250mm')),
(PAGE_SIZE_B4, (u'250mm', u'353mm')),
(PAGE_SIZE_LETTER, (u'8.5in', u'11in')),
(PAGE_SIZE_LEGAL, (u'8.5in', u'14in')),
(PAGE_SIZE_LEDGER, (u'11in', u'17in'))
)

View File

@@ -1,14 +1,14 @@
{% load project_tags %}
{% load printing_tags %}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>{% project_name %}</title>
<style type="text/css">
{% comment %}
* {
padding: 0;
margin: 0;
@@ -34,21 +34,25 @@
left: 0;
margin: auto;
}
.break { page-break-before: always; }
{% endcomment %}
.break { page-break-after: always; }
img { border: 1px solid black; }
@page {
margin: 0cm;
size: {{ page_size.0 }} {{ page_size.1 }};
margin-top: 1cm;
margin-bottom: 1cm;
margin-left: auto;
margin-right: auto;
}
{media print{@page {size: landscape}}
</style>
<style>
@PAGE landscape {size: landscape;}
TABLE {PAGE: landscape;}
</style>
</head>
<body>
{% get_document_size object %}
{{ document_width }} {{ document_height }}
<img class="centered" src="{% url document_display_print object.id %}" {% if document_width > document_height %}width="100%"{% else %}height="100%"{% endif %} />
{% for page in object.documentpage_set.all %}
{% get_document_size object %}
<div class="{% if forloop.counter > 1 %}break{% endif %}">
<img src="{% url document_display_print object.id %}?page={{ page.page_number }}" {% if document_aspect > page_aspect %}width="97%"{% else %}height="97%"{% endif %} />
</div>
{% endfor %}
</body>
</html>

View File

@@ -14,7 +14,9 @@ class GetImageSizeNode(Node):
def render(self, context):
document = Variable(self.document).resolve(context)
arguments, warnings = calculate_converter_arguments(document, size=PRINT_SIZE, quality=QUALITY_PRINT)
context[u'document_width'], context['document_height'] = get_document_dimensions(document, **arguments)
width, height = get_document_dimensions(document, **arguments)
context[u'document_width'], context['document_height'] = width, height
context[u'document_aspect'] = float(width) / float(height)
return u''
@register.tag

View File

@@ -29,6 +29,7 @@ from tags.utils import get_tags_subtemplate
from document_comments.utils import get_comments_subtemplate
from converter.api import DEFAULT_ZOOM_LEVEL, DEFAULT_ROTATION, \
DEFAULT_FILE_FORMAT
from converter.api import QUALITY_PRINT
from documents.conf.settings import DELETE_STAGING_FILE_AFTER_UPLOAD
from documents.conf.settings import USE_STAGING_DIRECTORY
@@ -42,6 +43,7 @@ from documents.conf.settings import ZOOM_PERCENT_STEP
from documents.conf.settings import ZOOM_MAX_LEVEL
from documents.conf.settings import ZOOM_MIN_LEVEL
from documents.conf.settings import ROTATION_STEP
from documents.conf.settings import PRINT_SIZE
from documents import PERMISSION_DOCUMENT_CREATE, \
PERMISSION_DOCUMENT_PROPERTIES_EDIT, \
@@ -63,11 +65,9 @@ from documents.models import Document, DocumentType, DocumentPage, \
DocumentPageTransformation, RecentDocument, MetadataGroup
from documents.staging import StagingFile
from documents import metadata_group_link
PICTURE_ERROR_SMALL = u'picture_error.png'
PICTURE_ERROR_MEDIUM = u'1297211435_error.png'
PICTURE_UNKNOWN_SMALL = u'1299549572_unknown2.png'
PICTURE_UNKNOWN_MEDIUM = u'1299549805_unknown.png'
from documents.literals import PICTURE_ERROR_SMALL, PICTURE_ERROR_MEDIUM, \
PICTURE_UNKNOWN_SMALL, PICTURE_UNKNOWN_MEDIUM, PAGE_SIZE_DIMENSIONS, \
PAGE_SIZE_LETTER, PAGE_SIZE_LEGAL
def document_list(request, object_list=None, title=None):
@@ -1154,13 +1154,36 @@ def metadatagroup_view(request, document_id, metadata_group_id):
}, context_instance=RequestContext(request))
def document_print(request, document_id):
def document_print(request, document_id, page_size=PAGE_SIZE_LEGAL):
check_permissions(request.user, 'documents', [PERMISSION_DOCUMENT_VIEW])
document = get_object_or_404(Document.objects.select_related(), pk=document_id)
RecentDocument.objects.add_document_for_user(request.user, document)
#page = int(request.GET.get('page', 1))
#zoom = int(request.GET.get('zoom', 100))
#if zoom < ZOOM_MIN_LEVEL:
# zoom = ZOOM_MIN_LEVEL
#if zoom > ZOOM_MAX_LEVEL:
# zoom = ZOOM_MAX_LEVEL
#rotation = int(request.GET.get('rotation', 0)) % 360
arguments, warnings = calculate_converter_arguments(document, size=PRINT_SIZE, file_format=DEFAULT_FILE_FORMAT, quality=QUALITY_PRINT)
#, page=page, zoom=zoom, rotation=rotation)
#Pre-generate
output_file = convert_document(document, **arguments)
page_dimensions = dict(PAGE_SIZE_DIMENSIONS)[page_size]
width = float(page_dimensions[0].split('i')[0].split('c')[0].split('m')[0])
height = float(page_dimensions[1].split('i')[0].split('c')[0].split('m')[0])
return render_to_response('document_print.html', {
'object': document,
'page_size': page_dimensions,
'page_aspect': width / height,
'page_orientation': u'landscape' if width / height > 1 else u'portrait',
'page_orientation_landscape': True if width / height > 1 else False,
'page_orientation_portrait': False if width / height > 1 else True,
}, context_instance=RequestContext(request))