1 Star 0 Fork 0

yargs/pdfjs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

js

该项目通过iframe 的形式引入pdf.js, 原则上不管是不是vue,都可以使用

实现的功能:

  1. 解决pdf.js跨域问题
  2. 能够对pdf里的文本复制
  3. 选中内容后可以弹出操作提示框
  4. 实现搜索并定位
  5. 通过contentWindow方式跳转指定页面
iframe.contentWindow.PDFViewerApplication.pagesCount
iframe.contentWindow.PDFViewerApplication.page

// 注: 以下形式也可以跳转到指定页
// https://commoncms.ynyplt.cn/file-server/13648711629/9b613676-d867-47e3-873d-47d6d59015d5.pdf#page=1

java

controller

// 接口部分
@RequestMapping("/pdfdownload")
@ResponseBody
public void fileDownload(@RequestParam("filename") String filename,
                            HttpServletResponse response) throws UnsupportedEncodingException {
    // 通过网络获取文件流
    DownloadUtils.getFileStream(filename, response);
}

DownloadUtils

package com.example.mybatis.utils;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.net.ConnectException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;

public class DownloadUtils {
    // 下载工具部分
// 将文件流传送到response
    public static void getFileStream(String filename, HttpServletResponse response) {
        try {
            // 根据文件url下载文件
            openFile(filename, response);
        } catch (Exception e) {
            System.out.println("下载失败");
        }
    }

    // 通过url下载文件的方法
    private static void openFile(String filePath, HttpServletResponse response) {
        // 服务器状态
        int HttpResult;
        try {
            // URL
            URL url = new URL(filePath);
            // URL连接对象
            URLConnection urlconn = url.openConnection();
            urlconn.connect();
            HttpURLConnection httpconn = (HttpURLConnection) urlconn;
            HttpResult = httpconn.getResponseCode();
            if (HttpResult != HttpURLConnection.HTTP_OK) {
                System.out.println("网络连接失败");
                throw new ConnectException("网络连接失败");
            } else {
                InputStream in = urlconn.getInputStream();
                try {
                    String fileName = "test.pdf";
                    response.setContentType("application/pdf;charset=utf-8");
                    response.addHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\"");
                    int b = 0;
                    byte[] buffer = new byte[512];
                    while (b != -1) {
                        b = in.read(buffer);
                        if (b != -1) {
                            response.getOutputStream().write(buffer, 0, b);
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    System.out.println("文件取得失败");
                } finally {
                    try {
                        if (in != null) {
                            in.close();
                        }
                        response.getOutputStream().flush();
                    } catch (IOException e) {
                        e.printStackTrace();
                        System.out.println("文件取得失败");
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("文件取得失败");
        }
    }
}

空文件

简介

实现pdfjs一系列功能 展开 收起
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yargs/pdfjs.git
git@gitee.com:yargs/pdfjs.git
yargs
pdfjs
pdfjs
master

搜索帮助