< 戻る
印刷

PDFから切り抜いた画像を抽出

JPedalは、PDFファイルから切り抜いた画像を簡単に抽出する方法をいくつか提供しています。

コマンドラインまたは他の言語でPDFから切り抜いた画像を抽出

				
					java -jar <a href="https://www.intwk.co.jp/jpedal/" title="PDFドキュメントを扱う必要のあるJava開発者のためのPDFライブラリです。このライブラリは、PDFファイルを扱う際の一般的な問題を解決します。" hreflang="ja" onover-preload="1">jpedal</a>.jar --extractClippedImages 
inputFileOrDir outputDir <a href="https://files.idrsolutions.com/maven/site/jdeli/apidocs/com/idrsolutions/image/encoder/OutputFormat.html" target="_blank" title="declaration: package: com.idrsolutions.image.encoder, enum: OutputFormat">outputFormat</a> outputHeight subDirectory 
[outputHeight subDirectory]...
				
			

この例の最後の2つの変数では、画像を取り出したいサイズ(画像サイズで取り出したい場合は-1)と、その高さ値で取り出した画像を保存するディレクトリを指定できます。この2つの変数を繰り返すことで、複数のサイズを生成することができます。
以下は、オリジナルサイズのpng画像をoutputDir/rawディレクトリに、高さ100pxの画像をoutputDir/mediumディレクトリに、高さ50pxの画像をoutputDir/thumbnailディレクトリに出力する例です。

				
					java -jar <a href="https://www.intwk.co.jp/jpedal-portal/" title="JPEDAL-PORTAL - 株式会社インターワーク" hreflang="ja" onover-preload="1">jpedal</a>.jar --extractClippedImages 
inputFileOrDir outputDir outputFormat -1 raw 100 medium 50 thumbnail
				
			

JavaでPDFから切り抜いた画像を抽出

静的で便利なメソッド
				
					ExtractClippedImages.
writeAllClippedImagesToDir("inputFileOrDirectory", "outputDir" , 
"outpuImageFormat", new String[]{"imageHeightAsFloat", "subDirectoryForHeight"});
				
			
APIアクセス方法
				
					<a href="https://support.idrsolutions.com/jpedal/tutorials/extract-images/extract-clipped-images-from-pdf" target="_blank" title="JPedal provides several methods to allow easy extraction of clipped images that appear with PDF files." hreflang="en-US">ExtractClippedImages</a> extract=new ExtractClippedImages("C:/pdfs/mypdf.pdf");
//extract.setPassword("password");
if (extract.openPDFFile()) {
    int pageCount=extract.getPageCount();
    for (int page=1; page
				
			

この例ではJPedal ExtractClippedImagesクラスを使用しています。最後の変数は文字列配列で、コマンドラインで使用する imageHeight / subDirectoryForHeight と同様の方法で、一連の高さとサブディレクトリのペアを指定します。

ExtractClippedImagesは、BMP、PNG、JPG、TIFFなど、さまざまな画像形式で画像を出力できます。

MENU