From 519c0329b2bb9b0e1ac9a293e76ad8a5f4488812 Mon Sep 17 00:00:00 2001 From: John Factotum <50942278+johnfactotum@users.noreply.github.com> Date: Fri, 18 Oct 2024 13:39:40 +0800 Subject: [PATCH] PDF: improve metadata --- pdf.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pdf.js b/pdf.js index dbde8d9..5abf583 100644 --- a/pdf.js +++ b/pdf.js @@ -120,10 +120,19 @@ export const makePDF = async file => { const book = { rendition: { layout: 'pre-paginated' } } - const info = (await pdf.getMetadata())?.info + const { metadata, info } = await pdf.getMetadata() ?? {} + // TODO: for better results, parse `metadata.getRaw()` book.metadata = { - title: info?.Title, - author: info?.Author, + title: metadata?.get('dc:title') ?? info?.Title, + author: metadata?.get('dc:creator') ?? info?.Author, + contributor: metadata?.get('dc:contributor'), + description: metadata?.get('dc:description') ?? info?.Subject, + language: metadata?.get('dc:language'), + publisher: metadata?.get('dc:publisher'), + subject: metadata?.get('dc:subject'), + identifier: metadata?.get('dc:identifier'), + source: metadata?.get('dc:source'), + rights: metadata?.get('dc:rights'), } const outline = await pdf.getOutline()