0
0

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 PDFページの向きを判定 

Posted at

今日はSpire.PDF for Javaという無料のライブラリを活用して、PDFページの向きを判定する方法を紹介します。

下準備

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

f:id:lendoris:20210616144244p:plain

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

f:id:lendoris:20210616144252p:plain

```JAVA import com.spire.pdf.PdfDocument; import com.spire.pdf.PdfPageBase;

public class DetectPageOrientation {
public static void main(String[] args){
//PDFをロードします。
PdfDocument pdf = new PdfDocument();
pdf.loadFromFile("Fields.pdf");

    //初めのページを取得します。
    PdfPageBase page = pdf.getPages().get(0);

    // ページの幅と高さを比較します。
    if (page.getSize().getWidth()> page.getSize().getHeight()){
        System.out.println("ページは横向きです");
    }
    else{
        System.out.println("ページは縦向きです");
    }
}

}

<h4><strong>実行結果</strong></h4>
<p><img src="https://cdn-ak.f.st-hatena.com/images/fotolife/l/lendoris/20210616/20210616144909.png" alt="f:id:lendoris:20210616144909p:plain" width="290" height="183" loading="lazy" title="" class="hatena-fotolife" itemprop="image" /></p>
<p> </p>
0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?