Commit dec29271 authored by Randall Leeds's avatar Randall Leeds

Sort out the PDF metadata anew

parent 9211fccc
...@@ -6,20 +6,43 @@ class PDF extends Annotator.Plugin ...@@ -6,20 +6,43 @@ class PDF extends Annotator.Plugin
documentPromise: null documentPromise: null
pluginInit: -> pluginInit: ->
@documentPromise = new Promise (resolveDocument, rejectDocument) -> if PDFViewerApplication.loading
resolveDocumentAndCleanup = (evt) -> @documentLoaded = new Promise (resolve) ->
window.removeEventListener('documentload', resolveDocumentAndCleanup) finish = (evt) ->
debugger window.removeEventListener('documentload', finish)
resolveDocument(evt) resolve()
window.addEventListener('documentload', resolveDocument) window.addEventListener('documentload', finish)
else
@documentLoaded = Promise.resolve()
window.addEventListener('pagerendered', @onpagerendered) window.addEventListener('pagerendered', @onpagerendered)
destroy: -> destroy: ->
window.removeEventListener('pagerendered', @onpagerendered) window.removeEventListener('pagerendered', @onpagerendered)
uri: ->
@documentLoaded.then ->
PDFViewerApplication.url
getMetadata: -> getMetadata: ->
Promise.resolve({}) @documentLoaded.then ->
info = PDFViewerApplication.documentInfo
metadata = PDFViewerApplication.metadata
# Taken from PDFViewerApplication#load
if metadata?.has('dc:title') and metadata.get('dc:title') isnt 'Untitled'
title = metadata.get('dc:title')
else if info?['Title']
title = info['Title']
else
title = document.title
# This is an experimental URN,
# as per http://tools.ietf.org/html/rfc3406#section-3.0
urn = "urn:x-pdf:" + PDFViewerApplication.documentFingerprint
link = [{href: urn}, {href: PDFViewerApplication.url}]
return {title, link}
onpagerendered: => onpagerendered: =>
succeed = ({annotation, target}) -> succeed = ({annotation, target}) ->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment