2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Java HTMLをPDFに変換 

Posted at

今日は Spire.PDF for Javaという無料のライブラリを使って、HTMLをPDFに変換する方法を紹介します。今回はSpire.PDF for Java 3.6.6以上のバージョンが必要なので、要注意です。また、従来の方法とは違って、今度はGUI機能も必須だから、Xvfbといったようなプログラムをダウンロードしておいてください。

下準備

1.E-iceblueの公式サイトからFree Spire.PDF for Java無料版をダウンロードしてください。

f:id:lendoris:20210507154602p:plain

 

2.IDEを起動して新規プロジェクトを作成してから、インストールされたファイルにあった相応しいSpire.PDF.jarを参照に追加してください。

f:id:lendoris:20210507154606p:plain

```JAVA

import com.spire.pdf.graphics.PdfMargins;

import com.spire.pdf.htmlconverter.qt.HtmlConverter;

import com.spire.pdf.htmlconverter.qt.Size;

public class HtmltoPDF {

public static void main(String[] args) {

    //HTML を名付ます。

    String url = "https://www.google.com/";

    String fileName = "Result.pdf";

   

    String pluginPath = "D:/Qt/plugins_32";

    HtmlConverter.setPluginPath(pluginPath);

    //PDFで保存ます。

    HtmlConverter.convert(url, fileName, true, 1000000, new Size(600f, 900f), new PdfMargins(0));

}

}

<h4><strong>実行結果</strong></h4>
<p><img src="https://cdn-ak.f.st-hatena.com/images/fotolife/l/lendoris/20210507/20210507154732.png" alt="f:id:lendoris:20210507154732p:plain" title="" class="hatena-fotolife" itemprop="image" /></p>
<p><strong> </strong></p>
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?