Zum Fußzeileninhalt springen
IRONPDF NUTZEN

C# JPG zu PDF konvertieren (Code-Beispiel-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;
Imports 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#");
Imports IronPdf

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

' Selects all JPG/JPEG images in the folder 'assets'.
Dim images = System.IO.Directory.EnumerateFiles("assets").Where(Function(f) f.EndsWith(".jpg") OrElse 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.

Häufig gestellte Fragen

Wie kann ich JPG-Bilder in C# in PDF umwandeln?

Sie können JPG-Bilder in C# mit IronPDF in PDF umwandeln, indem Sie die ImageToPdfConverter-Klasse verwenden. Installieren Sie zuerst IronPDF über den NuGet Package Manager oder fügen Sie die DLL zu Ihrem Projekt hinzu und nutzen Sie dann seine Methoden, um Bilder mit minimalem Code umzuwandeln.

Welche Schritte sind erforderlich, um IronPDF für JPG-zu-PDF-Konvertierung in C# einzurichten?

Um IronPDF für die Umwandlung von JPG in PDF in C# einzurichten, beginnen Sie mit der Erstellung eines C#-Projekts in Visual Studio. Installieren Sie IronPDF über den NuGet Package Manager oder laden Sie die DLL von der offiziellen Website herunter und fügen Sie dann den IronPDF-Namespace in Ihrem Code hinzu, um auf seine Funktionalitäten zuzugreifen.

Kann ich mehrere JPG-Dateien in ein einzelnes PDF-Dokument mit C# umwandeln?

Ja, Sie können mehrere JPG-Dateien mit IronPDF in ein einzelnes PDF-Dokument in C# umwandeln. Enumerate die JPG-Dateien in einem Verzeichnis mit System.IO.Directory und übergeben Sie sie an die ImageToPdf-Methode, um sie zu einem einzigen PDF zu kompilieren.

Ist es möglich, andere Bildformate mit dieser Bibliothek in PDF umzuwandeln?

Ja, IronPDF unterstützt die Umwandlung verschiedener Bildformate, einschließlich PNG, TIFF, GIF, SVG und BMP, in PDF-Dokumente, zusätzlich zu JPG.

Wie gehe ich vor, wenn die JPG-zu-PDF-Konvertierung fehlschlägt?

Wenn die JPG-zu-PDF-Konvertierung mit IronPDF fehlschlägt, stellen Sie sicher, dass die Bibliothek korrekt installiert ist und die Bildpfade genau sind. Überprüfen Sie Ausnahmen im Code und konsultieren Sie die IronPDF-Dokumentation für Tipps zur Fehlersuche.

Was sind die Voraussetzungen für die Verwendung von IronPDF in einem C#-Projekt?

Um IronPDF in einem C#-Projekt zu verwenden, benötigen Sie eine Entwicklungsumgebung wie Visual Studio mit .NET Core 6.0 oder höher und ein grundlegendes Verständnis der C#-Programmierung und Windows-Anwendungen.

Kann ich IronPDF verwenden, um die aus JPG-Bildern erstellten PDF-Dokumente zu sichern?

Ja, IronPDF erlaubt es Ihnen, Verschlüsselungen anzuwenden und Berechtigungen auf von JPG-Bildern erstellten PDF-Dokumenten zu setzen, um die Dokumentensicherheit und den Zugriffssteuerung zu verbessern.

Bietet IronPDF zusätzliche Funktionen neben der Bild-zu-PDF-Konvertierung?

Ja, IronPDF bietet eine Vielzahl von Funktionen, einschließlich der Möglichkeit, PDFs aus HTML zu erstellen, vorhandene PDFs durch Hinzufügen von Kopfzeilen, Fußzeilen und Stempeln zu bearbeiten und mehrere PDF-Dokumente zusammenzuführen.

Kann IronPDF HTML-Inhalte in PDF umwandeln?

Ja, IronPDF kann HTML-Inhalte, einschließlich HTML5, JavaScript und CSS, in PDF-Dokumente umwandeln. Diese Funktionalität ist nützlich, um das Layout und die Stile von Webseiten im PDF-Format zu erhalten.

Gibt es eine Testversion von IronPDF zum Ausprobieren?

Ja, IronPDF bietet eine kostenlose Testversion, die verwendet werden kann, um seine Funktionen auszuprobieren, einschließlich der Umwandlung von Bildern in PDFs. Ein kostenloser Testschlüssel kann auf deren offizieller Website erhalten werden.

Ist IronPDF bei der Konvertierung von JPG in PDF vollständig mit .NET 10 kompatibel?

Ja – IronPDF ist vollständig mit .NET 10 kompatibel. Es unterstützt die Bild-zu-PDF-Konvertierung, einschließlich JPGs, standardmäßig in .NET 10-Projekten, ohne dass Umwege oder benutzerdefinierte Konfigurationen erforderlich sind. Außerdem unterstützt es die plattformübergreifende Bereitstellung unter Windows, macOS und Linux unter .NET 10.

Curtis Chau
Technischer Autor

Curtis Chau hat einen Bachelor-Abschluss in Informatik von der Carleton University und ist spezialisiert auf Frontend-Entwicklung mit Expertise in Node.js, TypeScript, JavaScript und React. Leidenschaftlich widmet er sich der Erstellung intuitiver und ästhetisch ansprechender Benutzerschnittstellen und arbeitet gerne mit modernen Frameworks sowie der Erstellung gut strukturierter, optisch ansprechender ...

Weiterlesen