【问题标题】:Importing PDF causing an error of URIError: Pathname cannot be decoded导入 PDF 导致错误 URIError: Pathname cannot be decoded
【发布时间】:2021-04-16 21:22:42
【问题描述】:

我正在尝试为用户创建一个下载按钮以从浏览器下载 pdf。我在我的仓库中的一个文件夹中添加了 pdf 文件:

{
   test: /\.pdf$/,
   use: "raw-loader",
},

到我的 webpack 解决了它无法编译的问题。但现在我收到一个错误提示

URIError: Pathname "%PDF-1.7
... " could not be decoded. This is likely caused by an invalid percent-encoding.

我的组件很简单

import React from "react";
import CGXPDF from "../../images/SDPA_CGX.pdf";
import { Link } from "react-router-dom";

const PDFDownloadButton = ({ visitType }) => {

  return (
    <Link to={CGXPDF} target="_blank">Download Requisition Form</Link>
  );
};

我还是新手,所以我非常感谢任何帮助。 提前致谢!

【问题讨论】:

    标签: javascript reactjs pdf


    【解决方案1】:

    问题原来是我的 webpack 中的 use: "raw-loader"。将其更改为 use: ["file-loader"], 解决了此问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-18
      • 1970-01-01
      • 2015-04-09
      • 1970-01-01
      相关资源
      最近更新 更多