0
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 Word文書からPDFに変換

Posted at

Spire.Doc for Javaを利用することで、Wordファイルから、ただ数秒で様々なファイルに変換できます。これこそが、Javaでプログラミングを行う開発者にとって、とても使いやすいライブラリじゃないでしょうか。さあ、今回は、Word文書からPDFに変換する方法を紹介していきましょう!簡単なので、もしお役に立てば嬉しいと思います。

Spire.Doc for Javaとは?

Spire. Doc for Javaは、E-iceblue社が開発され、開発者が JavaプラットホームでWordのドキュメントを迅速かつ高品質で作成・編集・変換印刷するために設計された専門的なDoc処理APIです。

この製品は、商用版と無料版のFree.Spire.Doc for javaがあります。Spire.Doc for Javaは商用版ではありますが、基本的な機能を搭載しているので、無料試用で日常の仕事にはもう結構だと思います。

下準備

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

f:id:lendoris:20210928111333p:plain

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

Mavenの側なら?

もしMavenの利用者だったら、pom.xmlファイルに下記のようなコードを追加することで、JARを簡単にインポートできます。

```JAVA com.e-iceblue http://repo.e-iceblue.cn/repository/maven-public/ e-iceblue spire.Doc 4.9.0 ```

Method説明

WordからPDFに変換するには、主にdocument.saveToFile("out/toPDF.pdf", FileFormat.PDF);メソッドで実現します。詳しくは下記の表をご覧になってください。

 

           Method

                   説明

document.loadFromFile("Sample.docx");

 

        ファイルをロード

document.saveToFile("out/toPDF.pdf", FileFormat.PDF);

 

        PDF形式で保存

ステップ紹介

  • ステップ1:Documentのインスタンスを生成します。

Document document = new Document();

  • ステップ2:ファイルをロードします。

document.loadFromFile("Sample.docx");

  • テップ3:PDF形式で保存します。

document.saveToFile("out/toPDF.pdf", FileFormat.PDF);

コードスニペットをまとめて下記のフルコードになります。

```JAVA import com.spire.doc.*; public class WordtoPDF { public static void main(String[] args) {
    Document document = new Document();
    document.loadFromFile("Sample.docx");

    document.saveToFile("out/toPDF.pdf", FileFormat.PDF);

}

}

<h1><strong>元のファイル</strong></h1>
<p><img src="https://cdn-ak.f.st-hatena.com/images/fotolife/l/lendoris/20210928/20210928111627.png" alt="f:id:lendoris:20210928111627p:plain" width="554" height="596" loading="lazy" title="" class="hatena-fotolife" itemprop="image" /></p>
<h1><strong>実行結果</strong></h1>
<p><img src="https://cdn-ak.f.st-hatena.com/images/fotolife/l/lendoris/20210928/20210928111653.png" alt="f:id:lendoris:20210928111653p:plain" width="554" height="583" loading="lazy" title="" class="hatena-fotolife" itemprop="image" /></p>
<p><strong> </strong></p>
<h1><strong> </strong><strong>以下の関連記事もご参照</strong></h1>
<blockquote>
<p><strong>Word文書変換機能:<a href="https://www.e-iceblue.com/Tutorials/Java/Spire.Doc-for-Java/Program-Guide/Conversion/Java-Convert-HTML-to-PDF.html">Convert HTML to PDF in Java</a></strong></p>
<p><strong>Word文書の作成法:<a href="https://www.e-iceblue.com/Tutorials/Java/Spire.Doc-for-Java/Program-Guide/Document-Operation/Create-Word-Document-in-Java.html">Create a PDF Document in Java</a></strong></p>
<p><strong>Word文書を印刷:<a href="https://www.e-iceblue.com/Tutorials/Java/Spire.Doc-for-Java/Program-Guide/Print/Print-Word-Document-in-Java.html">Create a PDF Document in Java</a></strong></p>
</blockquote>
<h1><strong>終わりに</strong></h1>
<p><strong><a href="https://www.e-iceblue.com/Introduce/doc-for-java.html">Spire.Doc for Java</a>は、パワフルな機能を満載しているので、使いやすいし、開発者にとってかなり便利なツールですね。もし完全な機能を使いたいのなら、直接<a href="https://www.e-iceblue.com/">E-iceblue</a>に連絡していいんですよ。</strong></p>
<p><strong> </strong></p>
<div id="gtx-trans" style="position: absolute; left: 1070px; top: 3861.31px;">
<div class="gtx-trans-icon"> </div>
</div>
0
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
0
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?