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

相关推荐
旺仔流奶啊~几秒前
idea使用Screw工具一键生成数据库文档详解
java·数据库·intellij-idea
一瓢西湖水4 分钟前
CPU使用超过阈值分析
java·开发语言·jvm
Heo12 分钟前
这才称得上是提示词工程!
java·架构·代码规范
魔道不误砍柴功15 分钟前
Java Function 高级使用技巧:从工程实战中来
java·开发语言·python
不知名。。。。。。。。16 分钟前
仿muduo库实现高并发服务器----EventLoop与线程整合起来
java·开发语言·jvm
编程大师哥18 分钟前
JAVA 集合框架进阶
java·开发语言
TechFind19 分钟前
AI Agent 开发完整教程:从零到上线的实战指南
java·javascript
春日见21 分钟前
车载系统中的CPU与内存监管
java·开发语言·驱动开发·docker·计算机外设
用户25656761334621 分钟前
Android Input 系统事件分发机制深度解析
java
fengxin_rou22 分钟前
黑马点评实战篇|第六篇:秒杀优化
java·开发语言·数据库·redis·分布式