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
-----------
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:

View file

@ -25,29 +25,53 @@ def cover(pdf):
return page(pdf, 1)
def ql_cover(pdf):
tmp = tempfile.mkdtemp()
cmd = [
'qlmanage',
'-t',
'-s',
'1024',
'-o',
tmp,
pdf
]
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('qlmanage did not create cover for %s', pdf)
data = None
shutil.rmtree(tmp)
return data
tmp = tempfile.mkdtemp()
cmd = [
'qlmanage',
'-t',
'-s',
'1024',
'-o',
tmp,
pdf
]
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('qlmanage did not create cover for %s', pdf)
data = None
shutil.rmtree(tmp)
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):
image = tempfile.mkstemp('.jpg')[1]
cmd = [
@ -69,6 +93,7 @@ def page(pdf, page):
data = fd.read()
os.unlink(image)
return data
'''
def info(pdf):
data = {}

View file

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

View file

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

View file

@ -269,8 +269,15 @@ oml.ui.usersDialog = function() {
id: user.id,
nickname: data.value
}, 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'
})
.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) {
if (data.ids.length) {
selectItem($list);
@ -554,7 +569,8 @@ oml.ui.usersDialog = function() {
folder.items.length
? renderUserList(folder)
: renderSectionList(folder)
).appendTo($folders[index].$content)
)
.appendTo($folders[index].$content)
);
});