The backend returns the base64 code of pdf to the front end, and the front end is displayed with pdf.js. If there is Chinese in the pdf, the question will not be displayed.

display in pdf.js. There is a problem that Chinese is not displayed in pdf

var pdfData=atob("JVBERi0xLjQKJeLjz9MKNCAwIG9iago8PC9MZW5ndGggMTY2L0ZpbHRlci9GbGF0ZURlY29kZT4+c3RyZWFtCnicK+RyCuEyNlOwMDBTCEnhcg3hCuQyUvACiRoqGAAhiLQwMVIIyeXSdzNUMDRQCEnj0tAMyQKpRSgxUEjORdZkBDTP3MxQz9gQotNIwcgEpNMALF+UzqXRn9Zr7icVtLCHOf1p0tIQL5CRBgrpWIyNjgXSKWBn4bbQxNhIwdzSSM/EHO5UNAtdEktSrSi1xdKUgC1GBoamuoZGukamRFkFAA+OTv4KZW5kc3RyZWFtCmVuZG9iagoxIDAgb2JqCjw8L0dyb3VwPDwvVHlwZS9Hcm91cC9DUy9EZXZpY2VSR0IvUy9UcmFuc3BhcmVuY3k+Pi9QYXJlbnQgNSAwIFIvQ29udGVudHMgNCAwIFIvVHlwZS9QYWdlL1Jlc291cmNlczw8L1Byb2NTZXQgWy9QREYgL1RleHQgL0ltYWdlQiAvSW1hZ2VDIC9JbWFnZUldL0NvbG9yU3BhY2U8PC9DUy9EZXZpY2VSR0I+Pi9Gb250PDwvRjEgMiAwIFIvRjIgMyAwIFI+Pj4+L01lZGlhQm94WzAgMCA1OTUgODQyXT4+CmVuZG9iago2IDAgb2JqClsxIDAgUi9YWVogMCA4NTIgMF0KZW5kb2JqCjIgMCBvYmoKPDwvQmFzZUZvbnQvSGVsdmV0aWNhL1R5cGUvRm9udC9FbmNvZGluZy9XaW5BbnNpRW5jb2RpbmcvU3VidHlwZS9UeXBlMT4+CmVuZG9iago3IDAgb2JqCjw8L0ZvbnRCQm94IFstMjUgLTI1NCAxMDAwIDg4MF0vQ2FwSGVpZ2h0IDg4MC9TdHlsZTw8L1Bhbm9zZSgBBQICBAAAAAAAAAApPj4vVHlwZS9Gb250RGVzY3JpcHRvci9TdGV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VmCjAgMTMKMDAwMDAwMDAwMCA2NTUzNSBmIAowMDAwMDAwMjQ4IDAwMDAwIG4gCjAwMDAwMDA1MjYgMDAwMDAgbiAKMDAwMDAwMDk2OCAwMDAwMCBuIAowMDAwMDAwMDE1IDAwMDAwIG4gCjAwMDAwMDEwOTIgMDAwMDAgbiAKMDAwMDAwMDQ5MSAwMDAwMCBuIAowMDAwMDAwNjE0IDAwMDAwIG4gCjAwMDAwMDA4MDUgMDAwMDAgbiAKMDAwMDAwMTE1NSAwMDAwMCBuIAowMDAwMDAxMjA5IDAwMDAwIG4gCjAwMDAwMDEyNDIgMDAwMDAgbiAKMDAwMDAwMTM0NyAwMDAwMCBuIAp0cmFpbGVyCjw8L1Jvb3QgMTEgMCBSL0lEIFs8MDhjNzVmZDMwZWE4NjAwY2FkOTQ1NDA2ZDJiYWNmM2U+PDRmOTRlZTdlNTExMTg5Y2I2OWRjMjNiZjI3OWMwZmI4Pl0vSW5mbyAxMiAwIFIvU2l6ZSAxMz4+CnN0YXJ0eHJlZgoxNTA4CiUlRU9GCg==")

  pdfjsLib.GlobalWorkerOptions.workerSrc =
    "https://unpkg.com/pdfjs-dist@2.0.489/build/pdf.worker.min.js";

// pdfjsLib.cMapUrl = "./cmaps/";
// pdfjsLib.cMapPacked = true;
  // Opening PDF by passing its binary data as a string. It is still preferable
  // to use Uint8Array, but string or array-like structure will work too.
  pdfjsLib.getDocument({data: pdfData}).then(function getPdfHelloWorld(pdf) {
    // Fetch the first page.
    pdf.getPage(1).then(function getPageHelloWorld(page) {
      var scale = 1.5;
      var viewport = page.getViewport(scale);
      // Prepare canvas using PDF page dimensions.
      var canvas = document.getElementById("the-canvas");
      var context = canvas.getContext("2d");
      canvas.height = viewport.height;
      canvas.width = viewport.width;
      // Render PDF page into canvas context.
      var renderContext = {
        canvasContext: context,
        viewport: viewport
      };
      page.render(renderContext);
    });
  });

Screenshot on the page

should be in Chinese, but it is not displayed.

has Daniel ever encountered this kind of problem?

Mar.29,2021

attach a link to see https://blog.csdn.net/niedewa.


it is possible that there is a font format that is not supported by pdf. Try introducing pdf.js fonts

const CMAP_URL = 'https://unpkg.com/pdfjs-dist@2.0.489/cmaps/';
pdfjsLib.getDocument({
    data: pdfData,
    cMapUrl: CMAP_URL,
    cMapPacked: true,
    })
Menu