前言
把url網(wǎng)頁或本地文件html轉(zhuǎn)換pdf
一、html轉(zhuǎn)pdf
一)代碼實(shí)現(xiàn)
1.maven配置
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-html-cloud</artifactId>
<version>22.12.1</version>
</dependency>
2.代碼
本地文件 html轉(zhuǎn)pdf
可本地文件或url轉(zhuǎn)換文章來源:http://www.zghlxwxcb.cn/news/detail-736857.html
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布局設(shè)置
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配置文章來源地址http://www.zghlxwxcb.cn/news/detail-736857.html
到了這里,關(guān)于【aspose之三】【springboot】java使用aspose.html 的cloud版html轉(zhuǎn)pdf,html2pdf的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!