How to use pdf.worker.js locally in angular application

Discussão em 'Angular' iniciado por Raghavi, Setembro 12, 2025.

  1. Raghavi

    Raghavi Guest

    I am trying to render the pdf report in the Ui using angular 14. This working fine in some environments. But in some environments it is blocked by the firewall.

    Currently it is loading the internet. https://cdn.jsdelivr.net/npm/pdfjs-dist@2.7.570/es5/build/pdf.worker.js

    I have installed the package and tried to set the workerSrc locally and use it. Still its not working. Attaching the code for reference. Kindly suggest a work around for this issue. Thanks in advance!

    HTML Code

    viewPdfReport reads json from the api call.

    <pdf-viewer [src]="viewPdfReport"
    [render-text]="true"
    [original-size]="false"
    [show-all]="true" >
    </pdf-viewer>


    module.ts

    import * as PDFJS from "pdfjs-dist";
    PDFJS.GlobalWorkerOptions.workerSrc = "pdf.worker.js";


    angular.json

    "assets": [
    "src/favicon.ico",
    "src/assets",
    {
    "glob": "pdf.worker.*",
    "input": "node_modules/pdfjs-dist/build/",
    "output": ""
    }
    ]

    Continue reading...

Compartilhe esta Página