푸터 콘텐츠로 바로가기
IRONPDF 사용

C# Convert JPG to PDF (Code Example Tutorial)

This article will walk you through converting JPG formats to PDF format programmatically in C#, using the IronPDF library super fast.

Topics covered in the Tutorial

In this tutorial, the following topics will be covered:

  1. Introduction to the IronPDF Library
  2. Create a C# Project
  3. Install the IronPDF Library
    • Method 1: NuGet Package Manager Solution
    • Method 2: NuGet Package Manager Console
    • Method 3: Using the DLL file
  4. Add the IronPDF Namespace
  5. Convert JPG Images to PDF Documents
  6. Summary

Requirements when using IronPDF:

  • You should have basic knowledge of the C# language.
  • You should have a basic knowledge of Windows Applications.

1. Create a C# Project

Before starting, you should have some knowledge regarding top-level statements, as the basic code is extracted from C# 10.0.

Let's begin by creating a C# project.

  • Open Visual Studio.
  • Create a new C# Project.
  • Give a name to the project.
  • Select a .NET Core version for your project. It is recommended to use .NET 6.0 for this project.

2. Install the IronPDF Library

Method 1: NuGet Package Manager Solution

Visual Studio supplies the NuGet Package Manager to download NuGet packages in your projects. You can access it through the Tools Menu or by right-clicking your project in Solution Explorer.

C# Convert JPG to PDF (Code Example Tutorial), Figure 1: Open from Solution Explorer Open from Solution Explorer

Once the NuGet Package Manager Solution panel is open, search for the IronPDF library. Select install.

C# Convert JPG to PDF (Code Example Tutorial), Figure 2: Browse IronPDF Browse IronPDF

Method 2: NuGet Package Manager Console

The NuGet Package Manager Console can also be used to easily install the library. Administrative privileges are not required for installation. Use a NuGet command to install the IronPDF library in your project. Copy the code snippet in the NuGet Package Manager Console and press enter. The IronPDF library will be installed and ready to use in your project.

Install-Package IronPdf

Method 3: Using DLL File

You can also download the IronPDF .DLL file directly from the official website.

After unzipping the file, reference the library in your project by following these steps:

  • Right-click the Solution in the Solution Explorer
  • Select "Add" -> "Reference"
  • Browse for the IronPDF.dll library
  • Click OK

All done! IronPDF is downloaded, installed, and ready to use to convert JPG to PDF format.

3. Add the IronPDF Namespace

To use IronPDF features, you need to add the IronPDF namespace to your program. Add the provided line of code to the top of the file.

using IronPdf;
using IronPdf;
$vbLabelText   $csharpLabel

This will allow you to access the functions of the IronPDF library. You are required to add this line of code to every file to use the IronPDF features.

4. Convert JPG Images to PDF Format

The conversion of JPG images to PDF files can be achieved in a single line with IronPDF. The code is neat, clean, and understandable. This task can be achieved using IronPDF's ImageToPdfConverter method. Follow the steps below to convert any JPG image to a PDF document.

First, place all JPG file formats to be converted inside a folder named "assets" located in the directory of the project. The folder must be placed in the location: bin\Debug\net6.0.

Then using System.IO.Directory, enumerate the assets folder with all the JPG files and pass it to the ImageToPdf method for PDF conversion. The following code snippet helps convert JPG to PDF images and saves them to a new document.

using IronPdf;

Console.WriteLine("C# Convert Images (JPG to PDF) using IronPDF");

// Selects all JPG/JPEG images in the folder 'assets'.
var images = System.IO.Directory.EnumerateFiles("assets")
                                .Where(f => f.EndsWith(".jpg") || f.EndsWith(".jpeg"));

// Converting images to PDF and saving the result as "composite.pdf".
ImageToPdfConverter.ImageToPdf(images).SaveAs("composite.pdf");

// Print success message
Console.WriteLine("JPG successfully converted to PDF using C#");
using IronPdf;

Console.WriteLine("C# Convert Images (JPG to PDF) using IronPDF");

// Selects all JPG/JPEG images in the folder 'assets'.
var images = System.IO.Directory.EnumerateFiles("assets")
                                .Where(f => f.EndsWith(".jpg") || f.EndsWith(".jpeg"));

// Converting images to PDF and saving the result as "composite.pdf".
ImageToPdfConverter.ImageToPdf(images).SaveAs("composite.pdf");

// Print success message
Console.WriteLine("JPG successfully converted to PDF using C#");
$vbLabelText   $csharpLabel

In the above code snippet, the assets folder can contain multiple JPG images. Each image will be added to the PDF document as a separate page.

The same code example can be used to convert multiple JPG files. The output contains three JPG images in a PDF document.

C# Convert JPG to PDF (Code Example Tutorial), Figure 4: Multiple JPG Images to PDF Document Multiple JPG Images to PDF Document

5. Summary

This tutorial shows how to convert JPG images to PDF documents using the IronPDF C# library. The manipulation and formatting of PDF files become significantly effortless using the IronPDF library function. All that is required is just a few lines of code to create a PDF document from JPG files. This assists in sending all images in a single PDF document, conserving time in uploading and downloading. You can also convert TIFF and other image formats using IronPDF just like the JPG tutorial.

6. More About the IronPDF Library

The IronPDF .NET PDF Library solution is a dream for developers, particularly software engineers who use C#. Using this excellent Iron Software tool, you can easily create a core PDF library for .NET. IronPDF will ensure any PDF conversion from different formats is an effortless and time-saving process.

It also enables you to construct a PDF file using HTML5, JavaScript, and CSS efficiently. You can seamlessly edit, stamp, and add headers and footers to a PDF. Furthermore, it makes it very easy to read PDF text, extract images or convert images to PDF programmatically.

Some of the important features include:

This tutorial focused on the conversion of a JPG image to a PDF document. IronPDF supports almost every image format for conversion. Supported formats are JPG, PNG, TIFF, GIF, SVG, and BMP. You can try the free version of IronPDF to test it out and with a free trial key, you can test the functionality of IronPDF. Furthermore, the current special offer allows you to get five products from IronPDF for the price of just two! Information regarding licensing can be found on this IronPDF Licensing Information page.

자주 묻는 질문

C#에서 JPG 이미지를 PDF로 변환하려면 어떻게 해야 하나요?

IronPDF를 사용하여 C#에서 ImageToPdfConverter 클래스를 활용하여 JPG 이미지를 PDF로 변환할 수 있습니다. 먼저 NuGet 패키지 관리자를 통해 또는 프로젝트에 DLL을 추가하여 IronPDF를 설치한 다음, 해당 메서드를 사용하여 최소한의 코드로 이미지를 변환합니다.

C#에서 JPG를 PDF로 변환하기 위해 IronPDF를 설정하려면 어떤 단계가 필요하나요?

C#에서 JPG를 PDF로 변환하기 위해 IronPDF를 설정하려면 먼저 Visual Studio에서 C# 프로젝트를 생성하세요. NuGet 패키지 관리자를 통해 IronPDF를 설치하거나 공식 웹사이트에서 DLL을 다운로드한 다음 코드에 IronPDF 네임스페이스를 추가하여 해당 기능에 액세스합니다.

C#을 사용하여 여러 개의 JPG 파일을 하나의 PDF 문서로 변환할 수 있나요?

예, IronPDF를 사용하여 여러 개의 JPG 파일을 C#에서 단일 PDF 문서로 변환할 수 있습니다. System.IO.Directory를 사용하여 디렉터리에서 JPG 파일을 열거하고 ImageToPdf 메서드에 전달하여 단일 PDF로 컴파일합니다.

이 라이브러리로 다른 이미지 형식을 PDF로 변환할 수 있나요?

예, IronPDF는 JPG 외에도 PNG, TIFF, GIF, SVG, BMP를 포함한 다양한 이미지 형식을 PDF 문서로 변환할 수 있습니다.

JPG에서 PDF로 변환이 실패하는 경우 문제 해결을 어떻게 처리하나요?

IronPDF를 사용하여 JPG를 PDF로 변환하는 데 실패하는 경우 라이브러리가 올바르게 설치되어 있고 이미지 경로가 정확한지 확인하세요. 코드에 예외가 있는지 확인하고 IronPDF 문서에서 문제 해결 팁을 참조하세요.

C# 프로젝트에서 IronPDF를 사용하기 위한 전제 조건은 무엇인가요?

C# 프로젝트에서 IronPDF를 사용하려면 .NET Core 6.0 이상이 설치된 Visual Studio와 같은 개발 환경이 필요하며 C# 프로그래밍 및 Windows 애플리케이션에 대한 기본적인 이해가 있어야 합니다.

IronPDF를 사용하여 JPG 이미지로 만든 PDF 문서를 보호할 수 있나요?

예, IronPDF를 사용하면 JPG 이미지로 만든 PDF 문서에 암호화를 적용하고 권한을 설정하여 문서 보안 및 액세스 제어를 강화할 수 있습니다.

IronPDF는 이미지를 PDF로 변환하는 것 외에 추가 기능을 제공하나요?

예, IronPDF는 HTML에서 PDF를 만들고, 머리글, 바닥글, 스탬프를 추가하여 기존 PDF를 편집하고, 여러 PDF 문서를 병합하는 기능을 포함한 다양한 기능을 제공합니다.

IronPDF는 HTML 콘텐츠를 PDF로 변환할 수 있나요?

예, IronPDF는 HTML5, JavaScript, CSS를 포함한 HTML 콘텐츠를 PDF 문서로 변환할 수 있습니다. 이 기능은 웹 페이지의 레이아웃과 스타일을 PDF 형식으로 보존하는 데 유용합니다.

테스트할 수 있는 IronPDF 평가판이 있나요?

예, IronPDF는 이미지를 PDF로 변환하는 등 기능을 테스트하는 데 사용할 수 있는 무료 평가판을 제공합니다. 무료 평가판 키는 공식 웹사이트에서 받을 수 있습니다.

IronPDF는 JPG를 PDF로 변환할 때 .NET 10과 완벽하게 호환되나요?

예 - IronPDF는 .NET 10과 완벽하게 호환됩니다. 해결 방법이나 사용자 지정 구성 없이도 .NET 10 프로젝트에서 JPG를 포함한 이미지-PDF 변환을 즉시 지원합니다. 또한 .NET 10에서 Windows, macOS 및 Linux의 크로스 플랫폼 배포를 지원합니다.

커티스 차우
기술 문서 작성자

커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, Node.js, TypeScript, JavaScript, React를 전문으로 하는 프론트엔드 개발자입니다. 직관적이고 미적으로 뛰어난 사용자 인터페이스를 만드는 데 열정을 가진 그는 최신 프레임워크를 활용하고, 잘 구성되고 시각적으로 매력적인 매뉴얼을 제작하는 것을 즐깁니다.

커티스는 개발 분야 외에도 사물 인터넷(IoT)에 깊은 관심을 가지고 있으며, 하드웨어와 소프트웨어를 통합하는 혁신적인 방법을 연구합니다. 여가 시간에는 게임을 즐기거나 디스코드 봇을 만들면서 기술에 대한 애정과 창의성을 결합합니다.