It’s quick and simple to convert HTML to PDF with Prince. HTML is seamlessly transformed into documents you can print
下載地址
Prince - Download Prince
系統名稱 | x86_64 | arm64 | 說明 |
Windows | 有 | - | |
Red Hat Enterprise Linux 7-9 | 有 | - | |
Ubuntu 18-22 | 有 | 有 | |
Debian GNU Linux 9-10 | 有 | - | |
Debian GNU Linux 11-12 | 有 | 有 | |
OpenSUSE | 有 | - | |
MacOS | ? | ? | |
Alpine Linux | 有 | - | |
Generic Linux | 有 | 有 | |
Free BSD | 有 | - |
<dependency>
<groupId>com.princexml</groupId>
<artifactId>prince-java-wrapper</artifactId>
<version>1.3.0</version>
</dependency>
// 獲取 java 版本
String version=System.getProperty("java.specification.version");
// 獲取系統類型
String platform=System.getProperty("os.name", "");
platform=platform.toLowerCase().contains("window") ? "win" : "linux";
// 當前程序目錄
String current=System.getProperty("user.dir");
System.out.println(String.format("current=%s", current));
// html 文件路徑
File index=Paths.get(current, "..", "index.html").toFile();
if (!index.exists()) {
System.out.println(String.format("file not exist,file=%s", index.getAbsolutePath()));
return;
}
String command=Paths.get(current, "..", "prince-15.2-win64", "bin", "prince.exe").toString();
if (OSInfo.getOSType()==OSInfo.OSType.LINUX) {
command="prince";
}
Prince prince=new Prince(command);
// prince.setLog("/path/to/log.txt");
// prince.addStyleSheet("/path/to/stylesheet.css");
// prince.addScript("/path/to/script.js");
prince.setJavaScript(true);
try {
// 轉換 html 文件
File file=Paths.get(current, String.format("java%s_%s.pdf", version, platform)).toFile();
prince.convert(index.getAbsolutePath(), file.getAbsolutePath());
} catch (IOException e) {
e.printStackTrace();
}
prince-demo/java1.8_win.pdf · yjihrp/linux-html2pdf-demo - Gitee.com
prince-demo/java11_linux.pdf · yjihrp/linux-html2pdf-demo - Gitee.com
下一篇 2-LINUX HTML 轉 PDF-itext5、8
pire.Doc for Java 是一款專業的Java Word組件,開發人員使用它可以輕松地將Word文檔創建、讀取、編輯、轉換和打印等功能集成到自己的Java應用程序中。
本文介紹使用Spire.Doc for Java將WPS文字文檔轉為PDF格式的方法。
Spire.Doc for Java官方最新版免費下載試用,歷史版本下載,在線文檔和幫助文件下載-慧都網
代碼如下:
import com.spire.doc.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
public class WordToPDF{
public static void main(String[] args)throws IOException {
//通過流加載WPS文字文檔
FileInputStream inputStream=new FileInputStream(new File("input.wps"));
Document document=new Document();
document.loadFromStream(inputStream, FileFormat.Doc);
//保存為PDF
document.saveToFile("WPStoPDF.pdf",FileFormat.PDF);
}
}
原WPS文字文檔:
轉換后的WPS文字文檔:
Spire.Doc for Java 4.7.0已發布。該版本增強了轉換Word/RTF到PDF,以及轉換HTML到Word的功能。此外,本次更新還修復了加載和保存Word文檔等時出現的問題。
DF是一種比較穩定的電子文檔格式,而HTML則是一種通用的網頁格式,如何才能實現這兩種格式之間的互轉呢?
首先將網頁轉成PDF是相當來說比較簡單的操作,而且只要我們對PDF格式比較熟悉,一定都知道PDF虛擬打印機可以將各種格式打印并以PDF格式保存,所以此方法也同樣適用于HTML轉換PDF,具體操作方法就是先打開網頁后,在網頁任意處右擊并選擇“打印”
接著在左上角的打印設置頁面,將目標打印機更改為電腦已有的PDF虛擬打印機或另存為PDF,再點擊保存并選擇文檔保存位置后就可以了。
而將PDF文件轉成網頁就需要使用一些工具了,先下載并安裝極速玩轉后,選擇PDF轉換中的PDF轉HTML進入轉換頁面,并添加需要轉換的PDF文檔。
然后在左下角的輸出路徑設置好轉換后的HTML網頁保存文件夾后,點擊右下角的開始轉換就可以了。
*請認真填寫需求信息,我們會在24小時內與您取得聯系。