PDF ツール NodeJSでPDFを画像に変換する方法 Curtis Chau 更新日:6月 22, 2025 Download IronPDF NuGet Download テキストの検索と置換 テキストと画像のスタンプ Start Free Trial Copy for LLMs Copy for LLMs Copy page as Markdown for LLMs Open in ChatGPT Ask ChatGPT about this page Open in Gemini Ask Gemini about this page Open in Grok Ask Grok about this page Open in Perplexity Ask Perplexity about this page Share Share on Facebook Share on X (Twitter) Share on LinkedIn Copy URL Email article Converting PDF documents to image formats such as PNG, JPG, GIF can be a valuable feature in various applications, ranging from document management systems to image processing software. In this article, we will learn how to convert PDF to image files using Node.js. We will leverage the power of a popular npm (Node Package Manager) package called pdf-poppler to achieve this task. 前提条件 First, make sure you have Node.js and npm (Node Package Manager) installed on your machine. You can check Node installations by running the following commands in your command prompt (cmd): node --version npm --version node --version npm --version SHELL If it is not installed, you will need to download it from the Node.js website. プロジェクトの設定 To get started, create a new directory for your project. For this tutorial, let's name this directory NodeJS_PDFtoImage. Next, navigate to it in the command prompt and initialize a new Node.js project by running: npm init -y npm init -y SHELL Running the above command will produce a package.json file that will allow us to install our project's required dependencies. Installing Dependencies The dependency we will use is pdf-poppler, a package that provides an easy-to-use API for converting PDFs to images. Install it by running the following command in Windows PowerShell or Command Prompt: npm install pdf-poppler npm install pdf-poppler SHELL これで完了です! Let's write the logic to convert PDF to images. Converting PDF to Image File Once the installation is complete, create a new file in our project's root directory and name it pdfToImage.js. Open the file in your preferred text editor, and add the required modules: const pdfPoppler = require('pdf-poppler'); A sample 28-page PDF file is shown below. Next, define a function called convertPdfToImage that takes in the path to the PDF file (pdfPath) and the output directory path (outputPath). This function will convert our sample PDF document into images. async function convertPdfToImage(pdfPath, outputPath) { const options = { format: 'jpeg', // You can choose other formats like png or tiff out_dir: outputPath, out_prefix: 'page', page: null // Specify the page number here to convert a specific page, otherwise null to convert all pages }; try { await pdfPoppler.convert(pdfPath, options); console.log('PDF converted to image successfully!'); } catch (error) { console.error('Error converting PDF to image:', error); } } The function uses the pdf-poppler package to convert the PDF to JPEG image format. We set the format option to 'jpeg' in this case, but you can choose other formats such as 'png' or 'tiff'. The out_dir option specifies the directory where the output images will be saved, and out_prefix sets a prefix for the output image files. The page option allows you to specify a particular page to convert, or you can leave it as null to convert all pages. To convert a PDF file to images, you can call the convertPdfToImage function with the appropriate file paths. 例えば: const pdfPath = '/path/to/input.pdf'; const outputPath = '/path/to/output/folder'; convertPdfToImage(pdfPath, outputPath); Note: Replace pdfPath value "/path/to/input.pdf" with the actual path to the input PDF file and "/path/to/output/folder" with the desired output directory path. 完全なコードは次のとおりです。 const pdfPoppler = require('pdf-poppler'); const pdfPath = 'C:\\Users\\hp\\Desktop\\NodeJS_PDFtoImage\\pdf_files\\input.pdf'; const outputDir = 'C:\\Users\\hp\\Desktop\\NodeJS_PDFtoImage\\pdf_images'; async function convertPdfToImage(pdfPath, outputPath) { const opts = { format: 'jpeg', // You can choose other formats like png or tiff out_dir: outputPath, out_prefix: 'page', page: null // Specify the page number here to convert a specific page, otherwise null to convert all pages }; try { await pdfPoppler.convert(pdfPath, opts); console.log('PDF converted to image successfully!'); } catch (error) { console.error('Error converting PDF to image:', error); } } convertPdfToImage(pdfPath, outputDir); Execute the Node.js Script Run the Node.js script by executing the following command: node pdfToImage.js node pdfToImage.js SHELL This will run the Node.js script and convert the PDF to image files using pdf-poppler. Output Folder Rasterize PDF File to Image in C# IronPDF for C# .NET IronPDF is a versatile .NET library that allows C# developers to work with PDF documents on the fly. It provides comprehensive features for creating, manipulating, and converting PDF files within C#. IronPDF offers a convenient way to convert PDF documents into image files using C#. This functionality is particularly useful when there is a need to extract images or generate image thumbnails from PDF files programmatically. To convert to images using IronPDF, you can follow the steps in the code snippet below: using IronPdf; using IronSoftware.Drawing; var pdf = PdfDocument.FromFile("input.pdf"); // Extract all pages to a folder as image files pdf.RasterizeToImageFiles(@"C:\image\folder\*.png"); // Dimensions and page ranges may be specified pdf.RasterizeToImageFiles(@"C:\image\folder\example_pdf_image_*.jpg", 100, 80); // Extract all pages as AnyBitmap objects AnyBitmap [] pdfBitmaps = pdf.ToBitmap(); using IronPdf; using IronSoftware.Drawing; var pdf = PdfDocument.FromFile("input.pdf"); // Extract all pages to a folder as image files pdf.RasterizeToImageFiles(@"C:\image\folder\*.png"); // Dimensions and page ranges may be specified pdf.RasterizeToImageFiles(@"C:\image\folder\example_pdf_image_*.jpg", 100, 80); // Extract all pages as AnyBitmap objects AnyBitmap [] pdfBitmaps = pdf.ToBitmap(); Imports IronPdf Imports IronSoftware.Drawing Private pdf = PdfDocument.FromFile("input.pdf") ' Extract all pages to a folder as image files pdf.RasterizeToImageFiles("C:\image\folder\*.png") ' Dimensions and page ranges may be specified pdf.RasterizeToImageFiles("C:\image\folder\example_pdf_image_*.jpg", 100, 80) ' Extract all pages as AnyBitmap objects Dim pdfBitmaps() As AnyBitmap = pdf.ToBitmap() $vbLabelText $csharpLabel This is how easy it is to convert PDF to image file using IronPDF. For more details on PDF to image conversion, please visit this code examples page. 結論 In this article, we explored how to convert PDF files to images in Node.js using the pdf-poppler package. By following the steps outlined, you can integrate PDF-to-image conversion capabilities into your Node.js applications, enabling a wide range of possibilities for handling and manipulating PDF documents programmatically. On the other hand, IronPDF is a powerful C# library that facilitates PDF manipulation and conversion tasks. Its ability to convert PDF to images offers a convenient way to extract images or generate image representations of PDF pages programmatically. By leveraging IronPDF's features, developers can seamlessly integrate PDF-to-image conversion functionality into their C# applications. IronPDF is free for development and can be licensed for commercial use. Moreover, you can also use it in commercial mode with a free trial. Curtis Chau 今すぐエンジニアリングチームとチャット テクニカルライター Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。開発以外にも、CurtisはIoT(Internet of Things)への強い関心を持ち、ハードウェアとソフトウェアの統合方法を模索しています。余暇には、ゲームをしたりDiscordボットを作成したりして、技術に対する愛情と創造性を組み合わせています。 関連する記事 更新日 6月 22, 2025 2025年の最高のPDF訂正ソフトウェアを発見する 2025年のトップPDF訂正ソリューションを探る。Adobe Acrobat Pro DC、Nitro PDF Pro、Foxit PDF Editor、およびPDF-XChange Editorを含みます。.NETでの自動訂正によるセキュリティとコンプライアンスの強化について学びます。 詳しく読む 更新日 6月 22, 2025 iPhone向けのベストPDFリーダー(無料&有料ツールの比較) この記事では、iPhoneの最高のPDFリーダーを調査し、IronPDFが最良の選択肢である理由を結論付けます。 詳しく読む 更新日 6月 26, 2025 Windows用のベスト無料PDFエディタ(無料&有料ツールの比較) この記事は、2025年に利用可能な最高の無料PDF編集ソフトを探り、最も強力で柔軟な選択肢であるIronPDFで締めくくります。 詳しく読む ChromeでPDFファイルを開く方法C++でPDFファイルを表示す...
更新日 6月 22, 2025 2025年の最高のPDF訂正ソフトウェアを発見する 2025年のトップPDF訂正ソリューションを探る。Adobe Acrobat Pro DC、Nitro PDF Pro、Foxit PDF Editor、およびPDF-XChange Editorを含みます。.NETでの自動訂正によるセキュリティとコンプライアンスの強化について学びます。 詳しく読む
更新日 6月 22, 2025 iPhone向けのベストPDFリーダー(無料&有料ツールの比較) この記事では、iPhoneの最高のPDFリーダーを調査し、IronPDFが最良の選択肢である理由を結論付けます。 詳しく読む
更新日 6月 26, 2025 Windows用のベスト無料PDFエディタ(無料&有料ツールの比較) この記事は、2025年に利用可能な最高の無料PDF編集ソフトを探り、最も強力で柔軟な選択肢であるIronPDFで締めくくります。 詳しく読む