NuGet을 통해 설치됨
PM> Install-Package Spire.PDF
관련된 링크들
더 쉬운 배포 또는 저장을 위해 하나의 파일로 결합하려는 여러 이미지가 있는 경우 이를 단일 PDF 문서로 변환하는 것이 훌륭한 솔루션입니다. 이 프로세스는 공간을 절약할 뿐만 아니라 모든 이미지가 하나의 파일에 함께 보관되어 공유 또는 전송이 편리해집니다. 이 기사에서는 다음 방법을 배웁니다 Spire.PDF for .NET사용하여 C# 및 VB.NET에서 여러 이미지를 단일 PDF 문서로 결합합니다.
Spire.PDF for .NET 설치
먼저 Spire.PDF for.NET 패키지에 포함된 DLL 파일을 .NET 프로젝트의 참조로 추가해야 합니다. DLL 파일은 이 링크에서 다운로드하거나 NuGet을 통해 설치할 수 있습니다.
PM> Install-Package Spire.PDF
C# 및 VB.NET에서 여러 이미지를 단일 PDF로 결합
폴더의 모든 이미지를 PDF로 변환하기 위해 각 이미지를 반복하고 이미지와 동일한 크기로 PDF에 새 페이지를 추가한 다음 새 페이지에 이미지를 그립니다. 자세한 단계는 다음과 같습니다.
- PdfDocument 개체를 만듭니다.
- PdfDocument.PageSettings.SetMargins() 메서드를 사용하여 페이지 여백을 0으로 설정합니다.
- 이미지가 저장된 폴더를 가져옵니다.
- 폴더의 각 이미지 파일을 반복하여 특정 이미지의 너비와 높이를 가져옵니다.
- PdfDocument.Pages.Add() 메서드를 사용하여 이미지와 너비 및 높이가 동일한 새 페이지를 PDF 문서에 추가합니다.
- PdfPageBase.Canvas.DrawImage() 메서드를 사용하여 페이지에 이미지를 그립니다.
- PdfDocument.SaveToFile() 메서드를 사용하여 문서를 저장합니다.
- C#
- VB.NET
using Spire.Pdf;
using Spire.Pdf.Graphics;
using System.Drawing;
namespace ConvertMultipleImagesIntoPdf
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument object
PdfDocument doc = new PdfDocument();
//Set the page margins to 0
doc.PageSettings.SetMargins(0);
//Get the folder where the images are stored
DirectoryInfo folder = new DirectoryInfo(@"C:\Users\Administrator\Desktop\Images");
//Iterate through the files in the folder
foreach (FileInfo file in folder.GetFiles())
{
//Load a particular image
Image image = Image.FromFile(file.FullName);
//Get the image width and height
float width = image.PhysicalDimension.Width;
float height = image.PhysicalDimension.Height;
//Add a page that has the same size as the image
PdfPageBase page = doc.Pages.Add(new SizeF(width, height));
//Create a PdfImage object based on the image
PdfImage pdfImage = PdfImage.FromImage(image);
//Draw image at (0, 0) of the page
page.Canvas.DrawImage(pdfImage, 0, 0, pdfImage.Width, pdfImage.Height);
}
//Save to file
doc.SaveToFile("CombinaImagesToPdf.pdf");
doc.Dispose();
}
}
}

임시 라이센스 신청
생성된 문서에서 평가 메시지를 제거하고 싶거나, 기능 제한을 없애고 싶다면 30일 평가판 라이센스 요청 자신을 위해.