【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配置

相关推荐
B612 little star king13 分钟前
力扣29. 两数相除题解
java·算法·leetcode
野犬寒鸦14 分钟前
力扣hot100:环形链表(快慢指针法)(141)
java·数据结构·算法·leetcode·面试·职场和发展
上官浩仁19 分钟前
springboot synchronized 本地锁入门与实战
java·spring boot·spring
Gogo81620 分钟前
java与node.js对比
java·node.js
SmartJavaAI26 分钟前
Java调用Whisper和Vosk语音识别(ASR)模型,实现高效实时语音识别(附源码)
java·人工智能·whisper·语音识别
m0_7484613929 分钟前
Spring Boot + Vue 项目中使用 Redis 分布式锁案例
vue.js·spring boot·redis
山东小木29 分钟前
JBoltAI需求分析大师:基于SpringBoot的大模型智能需求文档生成解决方案
人工智能·spring boot·后端·需求分析·jboltai·javaai·aigs
用户37215742613530 分钟前
Python 高效实现 Word 转 PDF:告别 Office 依赖
java
渣哥35 分钟前
Java ThreadPoolExecutor 动态调整核心线程数:方法与注意事项
java
Miraitowa_cheems1 小时前
LeetCode算法日记 - Day 38: 二叉树的锯齿形层序遍历、二叉树最大宽度
java·linux·运维·算法·leetcode·链表·职场和发展