feat(reader): add PDF reader implementation
- Update pdfjs-wrapper.ts: add initializePDFReader() function - Configure PDF.js worker, standard fonts, and cmaps - Load PDF documents and extract metadata - Implement page rendering with canvas - Support PDF page navigation and zoom - Return PDFReader with current page tracking - Integrates with feature-based reader architecture
This commit is contained in:
@@ -95,6 +95,38 @@ export async function getPDFPage(
|
||||
return page;
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// Reader Initialization
|
||||
// ============================================================
|
||||
interface ReaderMetadata {
|
||||
media_item_id: string;
|
||||
title: string;
|
||||
author: string;
|
||||
cover_image_path: string;
|
||||
library_type: "ebook" | "comic" | "manga" | "pdf";
|
||||
mime_type: string;
|
||||
file_path: string;
|
||||
total_pages?: number;
|
||||
}
|
||||
interface PDFReader {
|
||||
type: "pdf";
|
||||
doc: any;
|
||||
currentPage: number;
|
||||
}
|
||||
export async function initializePDFReader(
|
||||
metadata: ReaderMetadata,
|
||||
): Promise<PDFReader> {
|
||||
configurePDFJS();
|
||||
const response = await fetch(metadata.file_path);
|
||||
const pdfBlob = await response.blob();
|
||||
const pdfMetadata = await loadPDFDocument(pdfBlob);
|
||||
return {
|
||||
type: "pdf",
|
||||
doc: pdfState.doc,
|
||||
currentPage: 1,
|
||||
};
|
||||
}
|
||||
|
||||
export async function getPDFPageText(pageNumber: number): Promise<any> {
|
||||
const page = await getPDFPage(pageNumber);
|
||||
return await page.getTextContent();
|
||||
|
||||
Reference in New Issue
Block a user