use poppler pdftocairo for preview

This commit is contained in:
j 2014-05-25 14:44:07 +02:00
parent 04cdb8f5b5
commit b3caaf335a
5 changed files with 73 additions and 27 deletions

View file

@ -17,9 +17,9 @@ or SixSS (https://sixxs.net).
Development Development
----------- -----------
On Linux you need to always install python-imaging python-lxml ghostscript: On Linux you need to always install PIL, pyhon-lxml and poppler-utils:
apt-get install python-imaging python-lxml ghostscript poppler-utils apt-get install python-imaging python-lxml poppler-utils
Now checkout the source and prepare for use: Now checkout the source and prepare for use:

View file

@ -48,6 +48,30 @@ def ql_cover(pdf):
shutil.rmtree(tmp) shutil.rmtree(tmp)
return data return data
def page(pdf, page):
tmp = tempfile.mkdtemp()
cmd = [
'pdftocairo',
pdf,
'-jpeg',
'-f', str(page), '-l', str(page),
'-scale-to', '1024', '-cropbox',
os.path.join(tmp, 'page')
]
p = subprocess.Popen(cmd)
p.wait()
image = glob('%s/*' % tmp)
if image:
image = image[0]
with open(image, 'rb') as fd:
data = fd.read()
else:
logger.debug('pdftocairo %s %s', pdf, ' '.join(cmd))
data = None
shutil.rmtree(tmp)
return data
'''
def page(pdf, page): def page(pdf, page):
image = tempfile.mkstemp('.jpg')[1] image = tempfile.mkstemp('.jpg')[1]
cmd = [ cmd = [
@ -69,6 +93,7 @@ def page(pdf, page):
data = fd.read() data = fd.read()
os.unlink(image) os.unlink(image)
return data return data
'''
def info(pdf): def info(pdf):
data = {} data = {}

View file

@ -255,6 +255,7 @@ def editUser(data):
del p.info['nickname'] del p.info['nickname']
p.update_name() p.update_name()
p.save() p.save()
return p.json()
return {} return {}
actions.register(editUser, cache=False) actions.register(editUser, cache=False)

View file

@ -306,6 +306,10 @@ oml.ui.folders = function() {
}); });
}; };
that.updateUser = function(id, name) {s
// ...
};
oml.bindEvent({ oml.bindEvent({
activity: function(data) { activity: function(data) {
if (data.activity == 'import') { if (data.activity == 'import') {

View file

@ -269,8 +269,15 @@ oml.ui.usersDialog = function() {
id: user.id, id: user.id,
nickname: data.value nickname: data.value
}, function(result) { }, function(result) {
Ox.print('EDIT USER', result.data); Ox.print('EDIT USER', result.data, folder);
// ... // FIXME: ugly
Ox.forEach($lists, function($list) {
var selected = $list.options('selected');
if (selected.length) {
$list.value(user.id, 'name', result.data.name);
return false;
}
});
}); });
} }
}) })
@ -479,6 +486,14 @@ oml.ui.usersDialog = function() {
height: folder.items.length * 16 + 'px' height: folder.items.length * 16 + 'px'
}) })
.bindEvent({ .bindEvent({
move: function(data) {
Ox.print('MOVE', data)
oml.api.sortUsers({
ids: data.ids
}, function(result) {
Ox.print('USER ORDER CHANGED', result.data);
});
},
select: function(data) { select: function(data) {
if (data.ids.length) { if (data.ids.length) {
selectItem($list); selectItem($list);
@ -554,7 +569,8 @@ oml.ui.usersDialog = function() {
folder.items.length folder.items.length
? renderUserList(folder) ? renderUserList(folder)
: renderSectionList(folder) : renderSectionList(folder)
).appendTo($folders[index].$content) )
.appendTo($folders[index].$content)
); );
}); });