I need help figuring out how to load a PDF from a URL using the webPDFLoader. Can someone explain how to implement this? Any assistance would be greatly appreciated.
I am working on this task in nextjs. Where should I place the pdfUrl variable within the webPDFLoader section?
"use client";
import React, { useEffect } from "react";
import { WebPDFLoader } from "langchain/document_loaders/web/pdf";
import { guestPdfId } from "@/components/Hero";
import { Document } from "react-pdf";
const bucketId = process.env.NEXT_PUBLIC_APPWRITE_BUCKET_ID!;
const fileId = guestPdfId;
const projectId = process.env.NEXT_PUBLIC_APPWRITE_PROJECT_ID!;
const pdfUrl = `https://cloud.appwrite.io/v1/storage/buckets/${bucketId}/files/${fileId}/view?project=${projectId}&mode=admin`;
// webPDFLoader
const blob = new Blob(); // e.g. from a file input
const loader = new WebPDFLoader(blob, {
// you may need to add `.then(m => m.default)` to the end of the import
pdfjs: () => import("pdfjs-dist/legacy/build/pdf.js"),
});
docs = loader.load()
const docLen = docs.length()
const ProcessPdf = () => {
return <div>
<button onClick={doclen}>Show PDF</button>
</div>;
};
export default ProcessPdf;