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

相关推荐
小小爱大王1 小时前
AI 编码效率提升 10 倍的秘密:Prompt 工程 + 工具链集成实战
java·javascript·人工智能
YUELEI1181 小时前
Springboot WebSocket
spring boot·后端·websocket
神龙斗士2401 小时前
继承和组合
java·开发语言
小蒜学长1 小时前
springboot基于JAVA的二手书籍交易系统的设计与实现(代码+数据库+LW)
java·数据库·spring boot·后端
菜鸟plus+2 小时前
Semaphore
java
小梁努力敲代码2 小时前
java数据结构--LinkedList与链表
java·数据结构·链表
それども2 小时前
IDEA Gradle并行编译内存溢出问题
java·ide·gradle·intellij-idea
滑水滑成滑头2 小时前
**发散创新:探索零信任网络下的安全编程实践**随着信息技术的飞速发展,网络安全问题日益凸显。传统的网络安全防护方式已难以
java·网络·python·安全·web安全
野犬寒鸦2 小时前
从零起步学习MySQL || 第七章:初识索引底层运用及性能优化(结合底层数据结构讲解)
java·数据库·后端·mysql·oracle