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

相关推荐
邪恶的贝利亚几秒前
定时器设计
java·linux·前端
工业互联网专业2 分钟前
基于springboot+vue的机场乘客服务系统
java·vue.js·spring boot·毕业设计·源码·课程设计·机场乘客服务系统
饕餮争锋3 分钟前
WebMvcConfigurer介绍-笔记
java·笔记·servlet
招风的黑耳9 分钟前
Java集合框架详解与使用场景示例
java·开发语言
xrkhy11 分钟前
java中XML的使用
xml·java·开发语言
胡斌附体21 分钟前
idea挂掉,会导致进程不结束,切换profile环境,导致token认证不通过
java·ide·intellij-idea·调试·token失效
y102121041 小时前
Pyhton训练营打卡Day27
java·开发语言·数据结构
AA-代码批发V哥1 小时前
Java类一文分解:JavaBean,工具类,测试类的深度剖析
java·开发语言
PHASELESS4111 小时前
HTML常用标签用法全解析:构建语义化网页的核心指南
前端·html
源码云商1 小时前
基于SpringBoot的校园周边美食探索及分享平台【附源码+数据库+文档下载】
数据库·spring boot·美食