egghunters / dxf-viewer-examples

Examples for the x-viewer SDK, which is a WebGL-based BIM model viewer built on Three.js and Vue3. It is used to view DWG/DXF/PDF files.
22 stars 8 forks source link

how to load pdf? #6

Open labman003 opened 3 months ago

labman003 commented 3 months ago

hello Can you provide some load pdf demo?

egghunters commented 2 months ago
        import { PdfLoaderPlugin, FontManager } from "@x-viewer/x-viewer";

        const config = {
            containerId: "myCanvas",
            enableSpinner: true,
            enableLayoutBar: true,
        };
        const viewer = new Viewer2d(config);
        const fontFiles = ["./libs/fonts/simplex.shx", "./libs/fonts/hztxt.shx"];
        await viewer.setFont(fontFiles);

        const modelCfg = {
            modelId: "id_0",
            name: "my sample",
            src: "http://www.abc.com/path/to/my-sample.pdf",
            merge: true,
        }
        const onProgress = (event) => {
            const progress = (event.loaded * 100) / event.total;
            console.log(`Loading '${modelCfg.modelId}' progress: ${progress.toFixed(1)}%`);
        };
        const pdfLoader = new PdfLoaderPlugin(viewer, { font: viewer.fontManager, pdfWorker: "libs/pdf/pdf.worker.min.js" });
        const model = await pdfLoader.loadAsync(modelCfg, onProgress);
        viewer.addModel(model);
labman003 commented 2 months ago
  1. How is this exception fixed? x-viewer.esm.min.js:6 Uncaught (in promise) DataCloneError: Failed to execute 'put' on 'IDBObjectStore': # could not be cloned. at eval (x-viewer.esm.min.js:6:1)

    2.Excuse me, do you provide pds.worker.js? I downloaded 2.5.207 but it didn't work

    image

    thanks!

    egghunters commented 1 month ago

    pdf.zip please try this