pdf 转html 在线预览和查询

方案一:
pdf2htmlex
package com.realize.controller;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSONObject;
import com.realize.util.MsgUtil;
import com.realize.util.OssUtil;
import com.realize.util.PdfConvertUtil;
import com.realize.util.StreamGobbler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.*;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;

@RestController
@Slf4j
public class ParserController {

    @GetMapping("/test")
    public String test() {
        return "test";
    }

//    @PostMapping("/parseHtml")
//    public JSONObject parseHtml(@ModelAttribute("htmlUrl") String htmlUrl) {
//        try (Playwright playwright = Playwright.create()) {
//            Browser browser = playwright.chromium().launch(new BrowserType.LaunchOptions().setHeadless(true));
//            Page page = browser.newPage();
//            String filePath = "/mnt/temp/html/" + RandomUtil.randomString(10) + ".html";
            String filePath = "/Users/sunyechen/IdeaProjects/realize-nacos/bin/" + RandomUtil.randomString(10) + ".html";
//            HttpUtil.downloadFile(htmlUrl, filePath);
//            page.navigate("file:" + filePath);
//            page.evaluate("var imgList=document.getElementsByTagName('img');" +
//                    "for(var i=0;i<imgList.length;i++){" +
//                    "var src=imgList[i].getAttribute('src');" +
//                    "imgList[i].setAttribute('src','https://realizedongmi.oss-cn-shanghai.aliyuncs.com/a-filings/test/'+src);" +
//                    "}");
//            JSONObject result = new JSONObject();
//            result.put("html", page.innerHTML("css=body"));
//            result.put("css", page.innerHTML("css=style"));
//            result.put("txt", page.innerText("css=body").trim().replaceAll("\n", ""));
//            page.close();
//            browser.close();
//            return result;
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return null;
//    }

    @GetMapping("/batchConvertPdf")
    public String batchConvertPdf() {
        String folderName = "/root/pdf";
        File folder = new File(folderName);
        File[] files = folder.listFiles();
        for (int i = 0; i < files.length; i++) {
            String fileName 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值