From a2a73034da37038da0109f31fc4f158bf81d80cb Mon Sep 17 00:00:00 2001 From: Roman Timashev Date: Sat, 29 Feb 2020 00:58:58 +0300 Subject: [PATCH] Document model pdf title stability improved (drop 0 byte from title value) --- modules/sync/sync/models/Document.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/modules/sync/sync/models/Document.py b/modules/sync/sync/models/Document.py index 0c989f5c..2eeb30ba 100644 --- a/modules/sync/sync/models/Document.py +++ b/modules/sync/sync/models/Document.py @@ -181,14 +181,21 @@ async def get_pdf_title(provider, file): from PyPDF2.generic import TextStringObject from PyPDF2.generic import IndirectObject + def t(value): + value = str(value) + value = value.replace('\u0000', '') + if value == 'None': + return None + return value + pdf = PdfFileReader(provider.read(file)) info = pdf.getDocumentInfo() if info: if type(info.title) == TextStringObject: - return str(info.title) + return t(info.title) if type(info.title_raw) == IndirectObject: o = pdf.getObject(info.title_raw) - return str(o) + return t(info.title) return None