Skip to content

Commit

Permalink
PDF: improve metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
johnfactotum committed Oct 18, 2024
1 parent f24e611 commit 519c032
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 519c032

Please sign in to comment.