[GH-ISSUE #1784] [FEAT]: Add Bookmarks to PDF Metadata in PDFLoader #1167

Closed
opened 2026-02-22 18:23:27 -05:00 by yindo · 1 comment
Owner

Originally created by @justinledwards on GitHub (Jun 28, 2024).
Original GitHub issue: https://github.com/Mintplex-Labs/anything-llm/issues/1784

Originally assigned to: @shatfield4 on GitHub.

What would you like to see?

In collector/processSingleFile/convert/asPDF.js

You could add the metadata for the chapter or bookmark by extending pdfjs to grab the extra metadata.

This would allow the user to find the relevant information or judge the relevancy of the information used by the llm more easily.

const pdfjsLib = require('pdfjs-dist');

class PDFLoader {
  constructor(filePath, options = {}) {
    this.filePath = filePath;
    this.options = options;
  }

  async load() {
    const loadingTask = pdfjsLib.getDocument(this.filePath);
    const pdf = await loadingTask.promise;

    const numPages = pdf.numPages;
    const pages = [];
    const metadata = await pdf.getMetadata();
    const outline = await pdf.getOutline();

    for (let i = 1; i <= numPages; i++) {
      const page = await pdf.getPage(i);
      const content = await page.getTextContent();
      const text = content.items.map(item => item.str).join(' ');

      pages.push({
        pageNumber: i,
        text,
        outline
      });
    }

    return {
      pages,
      metadata,
      outline
    };
  }
}

module.exports = PDFLoader;
Originally created by @justinledwards on GitHub (Jun 28, 2024). Original GitHub issue: https://github.com/Mintplex-Labs/anything-llm/issues/1784 Originally assigned to: @shatfield4 on GitHub. ### What would you like to see? In `collector/processSingleFile/convert/asPDF.js` You could add the metadata for the chapter or bookmark by extending pdfjs to grab the extra metadata. This would allow the user to find the relevant information or judge the relevancy of the information used by the llm more easily. ```javascript const pdfjsLib = require('pdfjs-dist'); class PDFLoader { constructor(filePath, options = {}) { this.filePath = filePath; this.options = options; } async load() { const loadingTask = pdfjsLib.getDocument(this.filePath); const pdf = await loadingTask.promise; const numPages = pdf.numPages; const pages = []; const metadata = await pdf.getMetadata(); const outline = await pdf.getOutline(); for (let i = 1; i <= numPages; i++) { const page = await pdf.getPage(i); const content = await page.getTextContent(); const text = content.items.map(item => item.str).join(' '); pages.push({ pageNumber: i, text, outline }); } return { pages, metadata, outline }; } } module.exports = PDFLoader; ```
yindo added the enhancementfeature request labels 2026-02-22 18:23:27 -05:00
yindo closed this issue 2026-02-22 18:23:27 -05:00
Author
Owner

@timothycarambat commented on GitHub (Jun 28, 2024):

Very cool! We will probably interface with pdfjs directly and rip out the simple LC loader we use right now so we can get this metadata and display it properly.

Related https://github.com/Mintplex-Labs/anything-llm/issues/392

@timothycarambat commented on GitHub (Jun 28, 2024): Very cool! We will probably interface with pdfjs directly and rip out the simple LC loader we use right now so we can get this metadata and display it properly. Related https://github.com/Mintplex-Labs/anything-llm/issues/392
yindo changed title from [FEAT]: Add Bookmarks to PDF Metadata in PDFLoader to [GH-ISSUE #1784] [FEAT]: Add Bookmarks to PDF Metadata in PDFLoader 2026-06-05 14:39:19 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mintplex-Labs/anything-llm#1167