Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

get metadata from pdf using javascript

hello what I’m trying to do is get metadata from a PDF file and modify it using the pdf-lib library
I tried this as in the documentation

But i gives me PDFDocument is not defined

I tried this as in the documentation

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<head>
    <meta charset="utf-8" />
    <script src="https://unpkg.com/pdf-lib@1.4.0"></script>
    <script src="https://unpkg.com/downloadjs@1.4.7"></script>
</head>

<body>
    <button onclick="get()">get </button>
</body>

<script>
    async function get() {
        const url = 'https://pdf-lib.js.org/assets/with_cropbox.pdf'
        const existingPdfBytes = await fetch(url).then(res => res.arrayBuffer())

        const pdfDoc = await PDFDocument.load(existingPdfBytes, {
            updateMetadata: false
        })
        console.log('Title:', pdfDoc.getTitle())
        console.log('Author:', pdfDoc.getAuthor())
        console.log('Subject:', pdfDoc.getSubject())
        console.log('Creator:', pdfDoc.getCreator())
        console.log('Keywords:', pdfDoc.getKeywords())
        console.log('Producer:', pdfDoc.getProducer())
        console.log('Creation Date:', pdfDoc.getCreationDate())
        console.log('Modification Date:', pdfDoc.getModificationDate()) };
</script>

</html>

>Solution :

Per the documentation, you need to use the library namespace, like so:

await PDFLib.PDFDocument.load(...)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading