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

相关推荐
Leo July1 小时前
【Java】Spring Security 6.x 全解析:从基础认证到企业级权限架构
java·spring·架构
星火开发设计2 小时前
C++ 数组:一维数组的定义、遍历与常见操作
java·开发语言·数据结构·c++·学习·数组·知识
码道功成2 小时前
Pycham及IntelliJ Idea常用插件
java·ide·intellij-idea
消失的旧时光-19432 小时前
第四篇(实战): 订单表索引设计实战:从慢 SQL 到毫秒级
java·数据库·sql
それども2 小时前
@ModelAttribute vs @RequestBody
java
雨中飘荡的记忆3 小时前
深度详解Spring Context
java·spring
Tao____3 小时前
JAVA开源物联网平台
java·物联网·mqtt·开源·ruoyi
yqd6663 小时前
SpringSecurity的使用
java·spring
仙俊红3 小时前
Java Map 家族核心解析
java·开发语言
一嘴一个橘子4 小时前
springMvc 接收参数、cookie、header
java