How can I display pdf file content with toolbar and sidebar in pdfjs-dist library [duplicate]

enter image description here

I want to show pdf content with toolbar as above, but it’s only show pdf, How can I configuration to show the toolbar?

that’s my step:

  1. I install pdfjs-dist: npm i pdfjs-dist
  2. my code:
    const pdfUrl = 'https://raw.githubusercontent.com/mozilla/pdf.js/ba2edeae/web/compressed.tracemonkey-pldi-09.pdf';

    let pdfDoc = null,
        pageNum = 1,
        scale = 0.4,
        canvas = document.getElementById('pdf-canvas'),
        ctx = canvas.getContext('2d'),
        pageRendering = false,
        pageNumPending = null;

function showPdf() {
        pdfjsLib.getDocument(pdfUrl).promise.then(function(pdfDoc_) {
            console.log(pdfDoc_);
            pdfDoc = pdfDoc_;
            document.getElementById('page_count').textContent = pdfDoc.numPages;

            // Initial/first page rendering
            renderPage(pageNum);
        });
    }

    function renderPage(num) {
        pageRendering = true;
        pdfDoc.getPage(num).then(function(page) {
            const viewport = page.getViewport({scale: scale});
            canvas.height = viewport.height;
            canvas.width = viewport.width;

            // Render PDF page into canvas context
            const renderContext = {
                canvasContext: ctx,
                viewport: viewport
            };
            const renderTask = page.render(renderContext);

            renderTask.promise.then(function() {
                pageRendering = false;
                if (pageNumPending !== null) {
                // New page rendering is pending
                renderPage(pageNumPending);
                pageNumPending = null;
                }
            });
        });
    }

html:

<button type="button" class="btn btn-outline-secondary" @click="showPdf();">PDF</button>

<div class="p-2 border">
    <canvas id="pdf-canvas"></canvas>
</div>

import:

import 'pdfjs-dist/build/pdf.min.mjs';
import * as pdfjsLib from 'pdfjs-dist/build/pdf.min.mjs';

pdfjsLib.GlobalWorkerOptions.workerSrc = `https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjsLib.version}/pdf.worker.min.js`;
window.pdfjsLib = pdfjsLib;

I try to customize a simple toolbar but take too much time, Somebody help..!
thanks

3

As mentioned in comments.

To control the PDF viewers appearance you can use a frame since all HyperText binary attachments, such as images, objects or embeds use inline frames.

Here we have an unmanaged <iframe> on the left and the browser supplies the PDF viewer. On the right we have a remote managed PDF.JS viewer thus it is a chosen frame in frame.

The difference between frame .pdf and .html you will need a server to provide all the bundled binary support from PDFjs-dist such as icons etc.

<iframe src="server/example.pdf" width="500" height="800">Served binary</iframe>
<iframe src="https://mozilla.github.io/pdf.js/web/viewer.html" width="500" height="800">PDF.JS viewer</iframe>

Note there are differences seen especially in colouration between a true PDF viewer on the left and PDF.JS emulation on the right.

Note also that using a JS viewer may encounter CORS restrictions so a browsers own PDF viewer may function but a remote one may not be allowed for security reasons.

With the PDF.js files including the viewer you simply add the input file.

<body>
<h1>PDF.js 'Hello, world!' example</h1>

iframe src="/public/web/viewer.html?file=helloworld.pdf"
<iframe src="/public/web/viewer.html?file=helloworld.pdf" width="500" height="800"> </iframe>
</body>

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật