【aspose之三】【springboot】java使用aspose.html 的cloud版html转pdf,html2pdf

前言

把url网页或本地文件html转换pdf

一、html转pdf

一)代码实现

1.maven配置

java 复制代码
    <dependency>
      <groupId>com.aspose</groupId>
      <artifactId>aspose-html-cloud</artifactId>
      <version>22.12.1</version>

    </dependency>

2.代码

本地文件 html转pdf

可本地文件或url转换

java 复制代码
   public static void html2pdf(){

        // Get keys from aspose site.
        // There is free quota available.
        // For more details, see https://purchase.aspose.cloud/pricing

        Configuration.setBasePath("https://api.aspose.cloud");
        Configuration.setAuthPath("https://api.aspose.cloud/connect/token");
        Configuration.setUserAgent("WebKit");
        Configuration.setDebug(true);

        HtmlApi api = new HtmlApi("你的密钥","你的clientId");

        String inputUrl = "https://stallman.org/articles/anonymous-payments-thru-phones.html";
        String outputFile = "./Output1.pdf";

        String inputFile = "./mark.html";


        JobBuilder builder = new ConverterBuilder()
//                .fromUrl(inputUrl)
                .fromLocalFile(inputFile)
                .saveToLocal(outputFile);

        OperationResult result = api.convert(builder);

//            String f2 = result.getFile();

        File dst = new File(result.getFile());

        if (dst.exists()) {
            System.out.println("Result file is " + dst);
        } else {
            System.out.println("Error conversion");
        }


    }

pdf布局设置

java 复制代码
PDFConversionOptions opt_A5 = new PDFConversionOptions()
                .setWidth(5.8)
                .setHeight(8.3)
                .setTopMargin(0.5)
                .setBottomMargin(0.5)
                .setLeftMargin(0.5)
                .setRightMargin(0.5)
                .setQuality(95);

2.密钥及配置
aspose配置

相关推荐
St_rive1 天前
Page Object设计模式
java·开发语言·设计模式
风流 少年1 天前
Spring AI 2.0:SSE
java·人工智能·spring
凤山老林1 天前
精细化流量治理:Spring Boot 动态特性开关与灰度发布体系
java·spring boot·后端
Eason_Lou1 天前
【无标题】
前端·vue.js·html
Aphelios3801 天前
一次锁内网络IO引发的Tomcat线程池“饿死”事故
java·开发语言·spring boot·elasticsearch·tomcat·网络io阻塞·线程池耗尽
不可求~1 天前
C++ std::string_view 不是字符串:从悬空引用到安全用法
java·开发语言·c++
Lam Tang1 天前
APS 系列文章10
java·代理模式
考虑考虑1 天前
Excel导入时产生特殊字符处理
java·后端·java ee
Scabbards_1 天前
面试Leetcode - Heap 堆
java·leetcode·面试
anOnion1 天前
构建无障碍组件之Menu and Menubar Pattern
前端·html·交互设计