这个东西做的我真的是头昏脑涨
主要需求是,upload上传pdf,pdf转图片格式展示,以图片格式上传到后端
封装了组件代码,父组件直接放就可以了
使用的插件pdfjs-dist,版本是 "pdfjs-dist": "2.5.207",node:14.13.0/18.17.0/16.14.2都可以你们要注意node版本是否跟这个插件版本匹配,因为node太老不支持pdfjs插件,而pdfjs插件至少要2.0左右的才会有文件worker.entry文件,本来我是4.0左右版本因为没有需要的文件,所以降下来的。
import React, { useState, useEffect, useRef } from 'react';
import { Spin, Pagination } from 'antd';
import { Form, UploadProps, Image } from "antd";
import { message, Modal, Upload, Button } from "antd";
import { useDispatch, useSelector } from 'react-redux';
import type RootState from '@/types/rootState';
import { getToken } from "@/utils/login";
import config from "@/utils/config";
import type { RcFile, UploadChangeParam } from "antd/lib/upload";
import type { UploadFile } from "antd/es/upload/interface";
import { Toast } from "antd-mobile";
import { LoadingOutlined, PlusOutlined } from "@ant-design/icons";
import type { PurchaseOrderAction } from "@/pages/purchase/purchaseOrder/model";
var pdfjsLib = require('pdfjs-dist/build/pdf.js');
import 'pdfjs-dist/build/pdf.worker.entry';
interface PdfViewerProps {
url: string;
}
const formItemLayout = {
labelCol: {
span: 3,
},
wrapperCol: {
span: 12,
},
};
const PdfViewer = () &