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

@ -25,29 +25,53 @@ def cover(pdf):
return page(pdf, 1) return page(pdf, 1)
def ql_cover(pdf): def ql_cover(pdf):
tmp = tempfile.mkdtemp() tmp = tempfile.mkdtemp()
cmd = [ cmd = [
'qlmanage', 'qlmanage',
'-t', '-t',
'-s', '-s',
'1024', '1024',
'-o', '-o',
tmp, tmp,
pdf pdf
] ]
p = subprocess.Popen(cmd) p = subprocess.Popen(cmd)
p.wait() p.wait()
image = glob('%s/*' % tmp) image = glob('%s/*' % tmp)
if image: if image:
image = image[0] image = image[0]
with open(image, 'rb') as fd: with open(image, 'rb') as fd:
data = fd.read() data = fd.read()
else: else:
logger.debug('qlmanage did not create cover for %s', pdf) logger.debug('qlmanage did not create cover for %s', pdf)
data = None data = None
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)
); );
}); });